Reputation: 2483
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.
Upvotes: 4
Views: 541
Reputation: 160833
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.
Upvotes: 4
Reputation: 121998
Try html()
which ovverides previous html in side the selector
$(selector).each(function() {
$(selector).html(htmlval); //ovverides previous html in side the selector
});
Upvotes: 1
Reputation: 1891
Try this
for (var i = 0; i < this.length; i++) {
$(this[i]).html(thehtmlval);
}
Upvotes: 1
Reputation: 2434
First we should know what this is.
For example if this is just a div, you could use the next code:
${'#myDivId'}.html(thehtmlval);
or
${this}.html(thehtmlval);
If you are trying to add a text, you can use the next one:
${'#myDivId'}.text(thehtmlval);
or
${this}.text(thehtmlval);
Upvotes: 1
Reputation: 36531
try this
$(this).html(thehtmlval);
if multiple then you can use jquery $.each()
Upvotes: 4