Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

Why is .each used with jQuery selector and then again with $(this)

$
0
0

I've got the following piece of code that I have amended to fit into my doc, and it works, but I don't understand why it uses .each twice? My comments in the code below should show where I'm confused.

function searchFunction(value) {
  //This cycles through each tr and runs the function
  $('#results tr').each(function() {
    var found = 'false';

    //$(this) then selects the tr and then runs through each tr (again!) for the If statement.    
    $(this).each(function() {
      if ($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0) {
        found = 'true';
      }
    });

    if (found === 'true') {
      $(this).show();
    } else {
      $(this).hide();
    }
  });
};

I've tried removing the second .each but the code breaks. Any help would be appreciated!

Thanks!


Viewing all articles
Browse latest Browse all 138249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>