2

A tutorial I'm working on has the following code with the following comment. I don't understand...

i) the comment, specifically, why it says "all second table cells." What does "second" mean? This isn`t proper English

ii) what is it looking for exactly when it says td + td? The program is about taking data from a table, so would td + td pick out anything between html table tags <td></td> for example?

//use querySelector to find all second table cells var cells = document.querySelectorAll("td + td"); 
1
  • Perhaps the second level of tds? Commented Mar 1, 2011 at 7:08

2 Answers 2

5

It's looking for only <td>s which are preceded by another <td> ( http://www.w3.org/TR/CSS2/selector.html#adjacent-selectors ).

So with this HTML, it would match <td>s 2-4 (inclusive):

<table> <tr> <td>Cell 1</td> <td>Cell 2</td> <td>Cell 3</td> <td>Cell 4</td> </tr> </table> 

An example here: http://jsfiddle.net/tMrbA/

Sign up to request clarification or add additional context in comments.

Comments

1

If you have a selector foo + bar, it will search for an element foo and then select all elements matching bar which are siblings coming after foo and have the same parent as foo.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.