| Author |
Trouble with the jQuery find method
|
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2542
|
|
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
|
|
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
|
|
|
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
|
|
Yup, I think it was filter() that you were thinking of.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Trouble with the jQuery find method
|
|
|