harsh harsh - 1 month ago 9
jQuery Question

How to re write innerHTML in jQuery

I have the following in my js.

for (var i = 0; i < this.length; i++) {
this[i].innerHTML = thehtmlval;
}


I want to write the same in jQuery.

I did some search and saw this but dont know how to apply it in this case. Can someone please help.

Answer Source

Assume this in your code is a NodeList:

$(this).each(function() {
  $(this).html(thehtmlval);
});

Or just: $(this).html(thehtmlval); because jQuery already did the loop for you inside.