Reputation: 829
I am trying to append a span element in a div tag using the below code .
$( document ).ready(function() {
$(".rocketchat-widget").append("<span class='tooltiptext'>Chat button</span>");
});
sometimes it works and adds the element.
But sometimes it doesn't load the element.
I am new to jquery so any help would be appreciable
Thank you
Upvotes: 0
Views: 163
Reputation: 382
Below is what you want, op (shahzad) was including third party widget on page load, as it is a third party widget sometimes it will load early or later, so, needed below code,
$( document ).ready(function() {
$(document).on("click", "[data-state=closed]" , function() { $(this).data('state', 'opened').attr('data-state', 'opened'); });
myVar = setInterval(function() {
if($(".rocketchat-widget").length){
$(".rocketchat-widget").append("<span class='tooltiptext'>Chat button</span>");
clearInterval(myVar);
}
}, 1000);
});
Upvotes: 1