I've got some DOM elements with attributes data-foo and data-bar.
Is there an elegant way to return only those elements that match on both attributes ?
At the moment I'm just using a filter, but maybe there's a better way
var result = $('[data-foo="aaa"]').filter('[data-bar="bbb"]');
Just join both selectors together
var result = $('[data-foo="aaa"][data-bar="bbb"]');
Just tack it on after the first one:
$('[data-foo="aaa"][data-bar="bbb"]');
http://jsfiddle.net/NaHwb/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With