Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

performance - Jquery - Insert HTML if element doesnt exist within every instance of certain element on page

I need to Insert HTML after a class if an element doesn't exist within every instance of a certain class on the page. More elements can be loaded into the page from a pagination that doesn't reload the page, but takes around 2-3 seconds to load content. So I was thinking id need something that looped every few seconds just in case the user changed page and more elements were loaded.

After messing around for a while and searching over stackoverflow, I got the code to add the element on page load working but I wasn't able to make it dynamic enough to add the elements if the users changed page using the pagination.

I tried a set interval function that checked for the visibility of the element then used .after to add code after the element. I couldn't get this working at all.

setInterval(function(){ 
    if ($('.CHECKFOR').visible(false)) {
        $('.BEFORECLASS').after('<span class="INSERTEDCLASS"></span>');  
  } else {
    clearInterval(interval);
  } 
}, 1000);

Any help would be really appreciated. Thank you.

question from:https://stackoverflow.com/questions/65941761/jquery-insert-html-if-element-doesnt-exist-within-every-instance-of-certain-el

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...