Xtian Xtian - 1 year ago 41
jQuery Question

match array with text in DIV

I have an array of names, which i need to see if they match names in a DIV:

var topicName = [];
$.each(top3, function(i, item) {
if (item.featured === false) {

$("DIV.grid_6 DIV.name").each(function(i, item){
if (topicName === item){
alert("do somethign");

I have a bunch of DIV.name classes and if the name matches the topicName array, i need to do something;

jk. jk.
Answer Source


<div class="name">jen</div>
<div class="name">bob</div>
<div class="name">sally</div> 


var topicName = ["jen","bob","michelle"];


    var nameFound = $.inArray($(this).text(), topicName);
    if (nameFound === -1){
        alert($(this).text() + " not found in array");
    } else {
        alert($(this).text() + " found in array");