Bug Tracker

Opened 15 years ago

Closed 15 years ago

#1906 closed bug (invalid)

about the method of $(el).contants('text') can't work

Reported by: joshua Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:


the method of $(el).contants('text') can't work in the version 1.2.1

Change History (5)

comment:1 Changed 15 years ago by davidserduke

What exactly are you trying to do? Do you mean contents()?

If you have

<p>Some text</p>

$("p").contents() will give the text node as a jQuery object. So

$("p").contents().get(0).nodeValue == $("p").text()

So can you give an example of what it doesn't do you expect it to? There is no documented parameter for contents() so I'm not sure what the 'text' is for.

comment:2 Changed 15 years ago by joshua

I'm sorry! It's my false; It's no bug. I spelt the 'contains' to 'contants'

comment:3 Changed 15 years ago by brandon

Resolution: invalid
Status: newclosed

comment:4 Changed 15 years ago by joshua

Resolution: invalid
Status: closedreopened

Content Filters: Name Type :contains(text) Returns: Array<Element> Matches elements which contain the given text.


<script src="jquery12.js"></script> <script> $(function(){

alert( $('p').contains('llo').html() );

}); </script> <p>Hello</p>


It cannot work when the jQuery's Version is 1.2 up.

The firefox show the error: $("p").contains is not a function.

(no name)()test.html (line 4)

to the wait list jQuery.readyList.push()jquery12.js (line 1911) (no name)()jquery12.js (line 1935) each([function()], function(), undefined)jquery12.js (line 562) ready()jquery12.js (line 1934)

[Break on this error] alert( $('p').contains('llo').html() );

comment:5 Changed 15 years ago by davidserduke

Resolution: invalid
Status: reopenedclosed

I think you are confused. There are two different "methods" available. One is contains which is a selector like:



Which will find all the <p> elements that have the text string 'llo' inside it. This sounds like the one you are looking for.

There is another called contents which is called like:



and this returns children of <p> including text nodes or if the target is an iframe then the nodes inside the iframe.

So again the problem is you are calling a function that doesn't exist. Hope that helps.

Note: See TracTickets for help on using tickets.