I have a div
with such content:
<div class="foobar">Red</div>
<div class="foobar">Yellow</div>
<div class="foobar">Cyan</div>
<div class="foobar">Luke Skywalker</div>
<div id="data"></div>
I use this jQuery function to replace text inside the divs. After all I append 2 more .foobar
divs to #data
:
$(function() {
$(".foobar").each(function() {
$(this).html("Black");
});
appendDiv();
});
function appendDiv() {
$("#data").append("<div class='foobar'>White</div>");
$("#data").append("<div class='foobar'>Orange</div>");
}
And here I don't know how to apply inited .each
function to appended divs. I've tried that, but it didn't worked for me:
$("#data").on("load", ".foobar", function(){
$(this).html("Black");
});
How to apply .each
function to appended html?