Without using 'on' or 'setInterval' or 'setTimeout' (none of them works), how do I change the text of an element that is dynamically generated after a certain button is clicked. So far I've tried the setInterval combined with setTimeout but it didn't work.
$("#buttontoclick").click(function(){
var changeElement = setInterval(function() {
var targetElement = $(".parentclass").find(".dynamicallygeneratedclass");
if (targetElement.length) {
clearInterval(changeElement); changeElement = 0;
targetElement.text('this is the new text');
};
setTimeout(function() {
if (changeElement) {
clearInterval(changeElement); changeElement = 0;
} else if (!changeElement) {
};
}, 5 * 1000);
});
});
I've also tried binding the dynamically generated child element with static parent element using 'on' but it didn't work either.
$(document).on('mouseover mouseout', '.dynamicallygeneratedclass', function(){
$('.dynamicallygeneratedclass').text('this is the new text');
});