Ticket #6672 (closed bug: wontfix)
Selectors not working properly for textNodes
| Reported by: | sharad.banka@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | selector | Version: | 1.4.2 |
| Keywords: | TextNodes, filter | Cc: | |
| Blocking: | Blocked by: |
Description
Hi, I am facing problems regarding selectors with text Node. I have a sample page like: <body>
Some text <div id='child'>
Some More Text
</div>
</body>
Now when I run the jQuery command: $("body").children().remove(); The page still shows "Some text". All the children arent removed. However $("body").contents().remove(), removes all content.
Also when I run this filter: awp$("body").contents().filter(function() {
return (this.id != 'child');}).remove();
I get the expected output "Some more text". However awp$("body").contents().filter('[id!=child]').remove() even thogh actually the same filter returns a faulty output "Some text. Some More text."
Conclusion: The filters dont properly select text Nodes.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

In the above case the text nodes are expected to not be selected. Please note the following based on the official jQuery documentation regarding .children():
"Note also that like most jQuery methods, .children() does not return text nodes; to get all children including text and comment nodes, use .contents()"
This is the currently agreed upon behaviour for .children() and a functional version of the original test with .contents() substituted for this solves the original problem experienced by the ticket submitter.
Test URL: http://jsfiddle.net/gfgEc/
Closing.