I can’t really get why the following selector works as expected (i.e. get the td):
table tr td
but this one doesn’t:
table > tr > td
The td is a descendant of tr, which in turn is a descendant of table, but they are also children of each other. Therefore, I thought that the > selector would work too.
I made two fiddles:
- Child: http://jsfiddle.net/brLee/
- Descendant: http://jsfiddle.net/brLee/1/
Why isn’t the > selector working here?
In HTML, browsers implicitly add a
tbodyelement within which to contain thetrelements1, so in reality,tris never a child oftable.Consequently, you have to do this instead:
Of course, if you add a
tbodyelement yourself, you use the same selector. The spec explains when atbodyis added implicitly otherwise:1 This is not the case for XHTML documents that are properly served as
application/xhtml+xml, however, given its XML roots.