PDA

View Full Version : filter out jquery loop



ggalan
01-31-2011, 10:41 PM
i have a jquery loop that looks like this.


var tagsArr=new Array();
$('.thumb_tag').each(function(){
var htmlStr = $(this).html();
$(htmlStr).find('a').each(function(){
tagsArr.push($(this).html().toLowerCase());

});
});

the line: tagsArr.push($(this).html().toLowerCase());
will find all 'a' elements of this loop and display it

my question:
how can i set a "filter" so that i can do something like this


if ($(htmlStr).find('a').match(/\bdesign\b/)){ // the \b is a word boundary and the word i want to only output is design
tagsArr.push($(this).html().toLowerCase());
}

ggalan
02-01-2011, 12:25 AM
in other words, if the element inside 'a' is


<a>design</a>


then perform this function


tagsArr.push($(this).html().toLowerCase());

ggalan
02-01-2011, 12:50 AM
tried this, but no luck


$('.thumb_tag').each(function(){
var htmlStr = $(this).html();
// $(htmlStr).find('a').each(function(){
var itm = $(htmlStr).find('a').each( function(){


if (itm.innerHTML == "design"){
tagsArr.push($(this).html().toLowerCase());

}

});
});