Results 1 to 3 of 3

Thread: filter out jquery loop

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default filter out jquery loop

    i have a jquery loop that looks like this.
    Code:
    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
    Code:
      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());
      }

  2. #2
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    in other words, if the element inside 'a' is
    Code:
    <a>design</a>
    then perform this function
    Code:
     tagsArr.push($(this).html().toLowerCase());

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    tried this, but no luck
    Code:
     $('.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());
    
         }
                
            });
        });

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •