Skip to content Skip to sidebar Skip to footer

Jquery Is Unable To Select Cells Outside Table

I know using outside is an invalid markup but it is still a node in HTML DOM. That is why I am able to see those two cells rendered. jQuery is unable to ge

Solution 1:

That is the browser doing its trick, nothing wrong with jQuery. The browser won't render the <tr> if its not within a table and will just strip off all the tags leaving out just plain text. Check your elements panel in browser to see the markup.. there is no element with a class of cell2

Solution 2:

Inspect the element, you'll see that the browser threw away the invalid markup and is just displaying the text.

enter image description here

Solution 3:

but it is still a node in HTML DOM

That's a wrong assumption, see 3.2.1 Semantics:

Authors must not use elements, attributes, or attribute values for purposes other than their appropriate intended semantic purpose, as doing so prevents software from correctly processing the page.

[...]

Authors must not use elements, attributes, or attribute values that are not permitted by this specification or other applicable specifications, as doing so makes it significantly harder for the language to be extended in the future.

Especially since the HTML5 recommendation dictates a specific parser behaviour, where <tr> gets only parsed correctly in the "in table" state.

See also:

Solution 4:

TR is only valid inside a TABLE. The browser is probably ignoring completely that part of the HTML.

You can always use the SCRIPT tag to put whatever you want inside

<scriptid="something"type="text/template"><tr><td>whatever</td></tr></script>

and use jQuery to recreate the element:

var tr = $( $('#something').html() );

Post a Comment for "Jquery Is Unable To Select Cells Outside Table"