I’m attempting to perform a function after an element ID becomes visible on a page. I want to make it so that when an element with the ID #discountbox becomes visible, then peform this function.
This is the javascript I’ve created so far:
JavaScript
x
10
10
1
jQuery(document).ready(checkContainer);
2
3
function checkContainer () {
4
if($('#discountbox').is(':visible'))){ //if the container is visible on the page
5
$("#discountbox").clone().insertAfter(".discount-summary");
6
} else {
7
setTimeout(checkContainer, 50); //wait 50 ms, then try again
8
}
9
}
10
Unfortunately, this does not appear to be working.
Advertisement
Answer
I’d tried you code here, and it works.
- what only i changed is just remove one ‘)'( maybe you alreay knew )
JavaScript
1
2
1
if($('#discountbox').is(':visible')))
2
to
JavaScript
1
2
1
if($('#discountbox').is(':visible'))
2