Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get innerHTML of each matched element

Tags:

jquery

each

I have a lot of <tr> elements. Each important one is marked with a class name containing "highlight-delete". How can I iterate over the whole set of them, and write each of their .innerHTML to the console? I tried this but it failed

            $.each('tr[class*=highlight-delete]', function (index, item) {
              console.log(item.innerHTML);
            });
like image 956
Travis J Avatar asked Oct 20 '25 02:10

Travis J


2 Answers

The first parameter of the each function should be an array or object, you are passing a string:

jQuery.each( collection, callback(indexInArray, valueOfElement) )

  $.each($('tr[class*=highlight-delete]'), function (index, item) {
          console.log(item.innerHTML);
  });
like image 177
undefined Avatar answered Oct 22 '25 04:10

undefined


You can use jquery's html() function

 $('tr[class*=highlight-delete]').each(function (index, item) {
      console.log($(item).html());
 });
like image 22
Gabe Avatar answered Oct 22 '25 03:10

Gabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!