aspose 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply 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
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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: 26201
    
  66

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
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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: 56220
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Trouble with the jQuery find method
 
Similar Threads
Looping JCheckBox
How to perform Calculation when a button a pressed in a Frame
create dynamic checkboxes
Why can't I get \n to work?
getParameterValues and TextArea inputs