Reputation: 1061
Instead of writing a loop like this:
$s.find("td.value").each(function() {
$(this).html($(this).attr("data-value"));
});
Is there a way to do this in one shot ? Something like:
$s.find("td.value").html($(this).attr("data-value"));
Upvotes: 0
Views: 31
Reputation: 123739
You can use the function argument of the html() to return the new html. But it doesn't make much difference since jquery internally loops through the items.
$s.find("td.value").html(function(){ //Has 2 arguments second one will be the current html representation of the element and first argument the index of the item in the collection
return $(this).data("value");
});
Upvotes: 1