Reputation: 759
How to select a object by data? I've found many examples but none of them seens work for me:
$('div').data('name', 'foo');
I've tried:
$('div').find('[data-name]="foo"').hide();
$('div[data-name]="foo"').hide();
$('div[name]="foo"').hide();
any idea?
Upvotes: 0
Views: 96
Reputation: 14302
Try this instead
$('div[data-name=foo]').hide()
Hope this will help !!
Upvotes: 2
Reputation: 13016
Use .attr
instead:
$('div').attr('data-name', 'foo');
$('div[data-name="foo"]').hide();
This article might be interesting to take a look at.
Upvotes: 0
Reputation: 337691
Try filter()
:
var $div = $('div').filter(function() {
return $(this).data('name') === 'foo';
});
$div.hide();
Upvotes: 2