Say if’ve got a set of items with some data on them like this:
<li data-filtro="website, web app"><a href="trabajos.php?id=84"><img src="imgs/thumbs/item_tn_84.jpg" /></a></li>
<li data-filtro="website, banners"><a href="trabajos.php?id=131"><img src="imgs/thumbs/item_tn_131.jpg" /></a></li>
<li data-filtro="publicidad"><a href="trabajos.php?id=22"><img src="imgs/thumbs/item_tn_22.jpg" /></a></li>
<li data-filtro="publicidad"><a href="trabajos.php?id=45"><img src="imgs/thumbs/item_tn_54.jpg" /></a></li>
And to filter some of the by their data content matching the value of a variable named ‘valor’, I’d like to do something like
var $set = $('li').filter(function(index){
return $(this).data('filtro').indexOf(valor) > -1;
});
But somehow I can’t make it work … do you guys have two minutes to open my eyes in this?
Thank you in advance!
I know this is a different solution, and maybe that’s not what you’re looking for, but you can use a selector for that: