Skip to main content

Bug Tracker

Side navigation

#11595 closed bug (invalid)

Opened April 17, 2012 03:45AM UTC

Closed April 17, 2012 12:25PM UTC

the filter of contents() can't get correct nodes

Reported by: 181652432@qq.com Owned by: 181652432@qq.com
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

example:

html:

<p>Hello <a href="http://ejohn.org/">John</a>, how are you doing?</p>

jquery:

$("p").contents().not("[nodeType=1]").wrap("<b/>");

then, the result should be:

<p><b>Hello</b> <a href="http://ejohn.org/">John</a>, <b>how are you doing?</b></p>

but in version 1.7.2, i get the result:

<p>Hello <b><a href="http://ejohn.org/">John</a></b>, how are you doing?</p>
Attachments (0)
Change History (5)

Changed April 17, 2012 03:48AM UTC by dmethvin comment:1

owner: → 181652432@qq.com
status: newpending

That's all kinds of broken. There is no nodeType *attribute* in your markup.

Please provide a jsFiddle.net example of what you are expecting.

Changed April 17, 2012 07:03AM UTC by 181652432@qq.com comment:2

status: pendingnew

Replying to [comment:1 dmethvin]:

That's all kinds of broken. There is no nodeType *attribute* in your markup. Please provide a jsFiddle.net example of what you are expecting.

I use the webkit browser.When I import the jquery of version 1.5.2, the Example is worked.When i update the jquery to version 1.7.2,it's not work.

I have the html:

<div>
menuName
<ul>
  <li>menu1</li>
  <li>menu2</li>
  <li>menu3</li>
</ul>
</div>

I got the menuName when i use the follow script(jquery-1.5.2).

script:

$("div").contents().not("[nodeType=1]").text()

but after i updated the jquery 1.7.2, i couldn't get it.

Changed April 17, 2012 07:18AM UTC by 181652432@qq.com comment:3

Replying to [comment:1 dmethvin]:

That's all kinds of broken. There is no nodeType *attribute* in your markup. Please provide a jsFiddle.net example of what you are expecting.

sorry,the comment:2 is not corrent.

so i provide the jsFiddle.net example..

jsFiddle:

example for 1.3.2: http://jsfiddle.net/hY2yL/1/

example for 1.7.2: http://jsfiddle.net/hY2yL/2/

Changed April 17, 2012 12:01PM UTC by anonymous comment:4

See bottom example:

http://api.jquery.com/contents/

The selector you're using is for attributes, not properties. I'm guessing the behaviour you're labeling "correct" in version 1.3.2 was actually not intended.

Changed April 17, 2012 12:25PM UTC by dmethvin comment:5

resolution: → invalid
status: newclosed

Agreed with anonymous, the fact that Sizzle grabbed properties as well as attributes was a bug.

Also, in general, jQuery does not support manipulation of text nodes. Many methods may either remove them or fail to work properly with them. Remember that CSS selectors cannot select text nodes.