File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Trouble with the jQuery find method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Trouble with the jQuery find method" Watch "Trouble with the jQuery find method" New topic
Author

Trouble with the jQuery find method

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2850
    
  11

I'm doing something wrong with searching inside a context. I'd expect something like $("input[name=somename]") to return the same set as $("input").find("[name=somename]") in all cases. However, on Bear's Operations Lab Page, I typed in:

$("input[name=checkboxes]")

Results:

4 matching elements:
INPUT#checkbox1
INPUT#checkbox2
INPUT#checkbox3
INPUT#checkbox4

Then I tried:
$("input").find("[name=checkboxes]")

Results:

0 matching elements:


I also tried $("[name=checkboxes]",$("input")), and also got 0 results. Where am I going wrong?


For reference:

$("input")

Results:

8 matching elements:
INPUT#aTextField
INPUT#radioA
INPUT#radioB
INPUT#radioC
INPUT#checkbox1
INPUT#checkbox2
INPUT#checkbox3
INPUT#checkbox4


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30499
    
150

Greg,
find() is supposed to match a descendant (child, grandchild, etc) of the matched node.

The following finds a bunch of li.


Since name="checkboxes" is an attribute on the attribute you have already matched and not a child, find() can't find it. But the original can because you are asking for attributes on the current element.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2850
    
  11

Oh, that's right. I knew I must be doing something fundamentally wrong. It's filter I want, right? Sigh, this will all sink in eventually. Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Yup, I think it was filter() that you were thinking of.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with the jQuery find method