My current challenge involves creating a function that checks for the visibility of the #discountbox element and then clones it to be placed after the .pricebox. However, I am encountering an issue where the cloning process continues indefinitely.
Any suggestions on how to modify the setInterval function so that it stops after finding #discountbox and cloning it once?
Here is a snippet of the HTML:
<div id="discountbox" class="discount-summary">
You get $5 Off
</div>
<div id="modal">
<span class="price-box">
$20.50
</span>
</div>
And here is the Javascript code:
jQuery(document).ready(addDiscountsummary);
function addDiscountsummary () {
if($('#discountbox').is(':visible')){
$("#discountbox").clone().insertAfter("#modal span.price-box");
} else {
setInterval(addDiscountsummary, 1000);
}
}