Ticket #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: | ||
| Blocking: | Blocked by: |
Description
the method of $(el).contants('text') can't work in the version 1.2.1
Change History
comment:2 Changed 6 years ago by joshua
I'm sorry! It's my false; It's no bug. I spelt the 'contains' to 'contants'
comment:3 Changed 6 years ago by brandon
- Status changed from new to closed
- Resolution set to invalid
comment:4 Changed 6 years ago by joshua
- Status changed from closed to reopened
- Resolution invalid deleted
Content Filters: Name Type :contains(text) Returns: Array<Element> Matches elements which contain the given text.
<code>
<script src="jquery12.js"></script> <script> $(function(){
alert( $('p').contains('llo').html() );
}); </script> <p>Hello</p>
</code>
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 5 years ago by davidserduke
- Status changed from reopened to closed
- Resolution set to invalid
I think you are confused. There are two different "methods" available. One is contains which is a selector like:
$("p:contains('llo')")
http://docs.jquery.com/Selectors/contains#text
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:
$("p").contents()
http://docs.jquery.com/Traversing/contents
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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.