I have a list kind of like below:
<p class='info' data-info='1'>Info 1 <span class='status'></span></p>
<p class='info' data-info='2'>Info 2 <span class='status'></span></p>
<p class='info' data-info='3'>Info 3 <span class='status'></span></p>......etc
What I need to do is run through all the .info elements and if the data-info number is included in an myArray change the span text. How, in jQuery do I match a value from inside an array ?
.infoelements and using theinArray()method to match the data attribute to the array content however I am not sure if usingeach()is the best practice.foriteration. But that's what.each()is there for.$('.info').each(function(){var element_to_match=$(this).data('info'); if($.inArray(element_to_match, myArray, 0)){//do the rest here....});- not tested this as yet and not used$.inArraybefore.