Reputation: 14600
How do I select a element using it's element type (Div), a class (spaceEvent) and a data attribute (data-event-id)?
here is an example of a element
<div class="spaceEvent" data-event-id=112>
and I want to find this element so that I can search for stuff inside it?
my guess would be something like
$("div.spaceEvent").find("[event-id=112]")
but I'm not sure!
Upvotes: 0
Views: 150
Reputation: 7295
You can use:
$('div.spaceEvent[data-event-id="112"]');
$('div.spaceEvent').filter('[data-event-id="112"]');
The find()
function searches the children, not itself. More details here.
Upvotes: 0
Reputation: 337647
Your selectors are almost correct, but you need to combine them in to a single jQuery object. Your use of find()
means that you're currently looking for a child element of the div instead of looking for a div with all the specified attributes.
Try this instead:
$('div.spaceEvent[data-event-id="112"]')
Upvotes: 1