Skip to main content

Bug Tracker

Side navigation

#1906 closed bug (invalid)

Opened November 09, 2007 10:51AM UTC

Closed November 30, 2007 04:02AM UTC

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:
Description

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

Attachments (0)
Change History (5)

Changed November 09, 2007 08:11PM UTC by davidserduke comment:1

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.

Changed November 13, 2007 01:49PM UTC by joshua comment:2

I'm sorry!

It's my false;

It's no bug.

I spelt the 'contains' to 'contants'

Changed November 14, 2007 04:35AM UTC by brandon comment:3

resolution: → invalid
status: newclosed

Changed November 15, 2007 08:05AM UTC by joshua comment:4

resolution: invalid
status: closedreopened

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() );

Changed November 30, 2007 04:02AM UTC by davidserduke comment:5

resolution: → invalid
status: reopenedclosed

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.