Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter() works differently from is()? #64

Closed
sophiebits opened this issue May 27, 2011 · 5 comments
Closed

filter() works differently from is()? #64

sophiebits opened this issue May 27, 2011 · 5 comments

Comments

@sophiebits
Copy link

Somehow this doesn't work. I'd expect to see in the console 1, true, 1, but instead it's 0 for the one using filter.

<html>
<head>
    <title>jQuery "filter" test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            console.log($("[data-test]").length);
            console.log($(document).children().eq(0).is("[data-test]"));
            console.log($(document).children().filter("[data-test]").length);
        });
    </script>
</head>
<body>
    <div data-test>Hi, I'm a div.</div>
</body>
</html>
@arextar
Copy link

arextar commented May 27, 2011

When you get the children of the document you get the HTML element only, try finding children of the body and it should work

@timmywil
Copy link
Member

As arexkun said, children only goes one level down, so you should expect 1, false, 0. http://jsfiddle.net/timmywil/HdwDW/

You can get support for jQuery on the #jquery irc channel or at http://forum.jquery.com/Using_jQuery.

@sophiebits
Copy link
Author

Okay, my MWE was clearly bad, but I did actually have a problem that made sense, I think.

Please take a look at this; thanks:

http://jsfiddle.net/feRqH/

(Also, ("#wrap").children().filter( ... ) fails in the same way; it's not just nextAll.)

@timmywil
Copy link
Member

Ah yes.
That is a known issue. We have a few tickets open related to that in the jQuery bug tracker: #9261, #7128, and #5637. We are tackling it in 1.7.

@sophiebits
Copy link
Author

Okay, thanks! It'll work for now if I just add the =. (Sorry for all the confusion!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants