Bug Tracker

Opened 8 years ago

Closed 8 years ago

#11595 closed bug (invalid)

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

Reported by: 181652432@… Owned by: 181652432@…
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>

Change History (5)

comment:1 Changed 8 years ago by dmethvin

Owner: set to 181652432@…
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.

comment:2 in reply to:  1 Changed 8 years ago by 181652432@…

Status: pendingnew

Replying to 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.

comment:3 in reply to:  1 Changed 8 years ago by 181652432@…

Replying to 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/

comment:4 Changed 8 years ago by anonymous

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.

comment:5 Changed 8 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.