I want to append the data only into a specific ID myID. It only prints the last value of the loop which is 3.
setInterval(sample, 2000);
function sample()
{
for(var i=0;i<=3;i++)
{
$('.found .find').each(function() {
if(this.id == "myID")
{
// if the ID of this element is equal to #myID
// this is the place where the data will append
$(this).empty();
$(this).append(i);
}
});
}
}
HTML:
<div class="found">
<div class="find" id="myID"></div>
</div>
<div class="found">
<div class="find" id="anID"></div>
</div>
<div class="found">
<div class="find" id="anID2"></div>
</div>
.empty(), which would remove previously appendedi.empty()it will not stop in appending data. Infinity$('#myDiv').val("0123");, why you are confused about the fact that.empty()is causing only the last value3to appear, why you need to loop through all of the.found .finddivs when theres a unique id.. maybe some clarification is in order?