Reputation: 723
I have the following code:
<div>
<div id="someID"><h1>Blah</h1></div>
<div id="someID2"><h1>Blah</h1></div>
</div>
and I am trying to select in jQuery (for the accordion in jQuery UI). However, the following does not work unless I remove the ID from the div.
$('> div > h1')
Is there some way to tell the selector to ignore the ID, or am I going about this the wrong way?
Edit: The actual use I'm going for is in the sortable accordion in jQuery UI, with IDs on the div elements. An example of what I'm doing, with source, can be found here:
http://jqueryui.com/demos/accordion/#sortable
Edit: As I have a feeling this may be related to jQueryUI, rather than the selectors themselves, below is the code I'm actually trying to run.
Working example without ID in div:
Upvotes: 1
Views: 1898
Reputation: 42808
http://codylindley.com/jqueryselectors/. A list of all jquery selectors. it should help you allot.
Upvotes: 1
Reputation: 63512
You could try selecting the <h1>
with a parent <div>
that has an id
attribute
$("div > div[id] > h1")
working example: http://jsfiddle.net/YjSvU/
ignores div
w/o id
: http://jsfiddle.net/YjSvU/1/
Upvotes: 2
Reputation: 490153
Your selector needs to be a string, so wrap it in single ('
) or double quotes ("
).
Also > div
does not make sense, as >
is direct descendant / child selector, and you have no parent on the left hand side (or otherwise context). Remove the leading >
.
See it not working on jsFiddle.
Upvotes: 1
Reputation: 4778
Use quotes, and im not sure about the first >
This should work:
$("div > h1")
Upvotes: 0