This demo code loops 3 times and every time appends text.
What I need is that text is not get appended but replaced, so that previously appended text should be removed before adding the new one.
I have tried a lot of things, nothing worked.
EDIT: You can’t add an extra tag after the span!
<div>
<span id="i_1">this is </span>
</div>
var i = 3;
while(i>0)
{
//// how to remove the text added on the previous iteration?
$("#i_1").after('text');
i--;
}
Piece of cake, that’s what the jQuery afterText Plugin is for.
Example/Demo:
jQuery afterText Plugin on github