Currently what I'm trying to do is have a function that looks for if the #discountbox element is visible then clone that #discountbox element and place it after .pricebox. Right now what's happening is that it is placing it after .pricebox and cloning it indefinitely.
How can I get the setInterval to stop after it finds #discountbox and clones it once?
HTML
<div id="discountbox" class="discount-summary">
      You get $5 Off
</div>
<div id="modal">
    <span class="price-box">
      $20.50
    </span>
</div>
Javascript
jQuery(document).ready(addDiscountsummary);
function addDiscountsummary () {
if($('#discountbox').is(':visible')){  //if the container is visible on the page
      $("#discountbox").clone().insertAfter("#modal span.price-box"); //insert add to cart button after view contents buttons     
    } else {
      setInterval(addDiscountsummary, 1000); //check every 1000 ms
    }
}
 
     
     
     
    