Reputation: 33644
I have the following html code:
<ul class="dropdown-menu shopping-cart-nav-drpdown">
<li class="item" data-item-id="58">
</li>
<li class="item" data-item-id="100">
</li>
<li class="item last">
<a href="/cart" class="btn btn-info full-button">View Cart</a>
</li>
</ul>
Inside this shopping-cart-nav-drpdown
, how do I find the li that has data-item-id=58? Is it possible to do this without iterating through all the children of ul and use getAttributes?
Upvotes: 0
Views: 127
Reputation: 157
try this
jQuery( ".shopping-cart-nav-drpdown li" ).each(function(){
if($(this).data('item-id')=="58"){
alert('found');
}
});
Upvotes: -1
Reputation: 73906
Yes, it is possible to do this without iterating through all the children of ul
:
$('.shopping-cart-nav-drpdown li[data-item-id="58"]');
You can also make it dynamic like this:
var data = 58;
$('.shopping-cart-nav-drpdown li[data-item-id="' + data + '"]');
Upvotes: 2