Search comma-separated list attribute using jQuery

I have an attribute that is comma-separated list, and I want to search for a particular value in that list


<img id=”img1” src=”somepic.jpg” tags=”nature,flower,color”>


Using jQuery, it’s simple to do, for example, I will search for the tag “nature” in the image

var exists = $.inArray(“nature”, $(“#img1”).attr(“tags”).split(',')) != -1;

Leave a Comment

Your email address will not be published. Required fields are marked *