0

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:

jQuery(document).ready(checkContainer);

function checkContainer () {
  if($('#discountbox').is(':visible'))){ //if the container is visible on the page
    $("#discountbox").clone().insertAfter(".discount-summary");
  } else {
    setTimeout(checkContainer, 50); //wait 50 ms, then try again
  }
}

Unfortunately, this does not appear to be working.

Felicia Santos
  • 341
  • 1
  • 10
  • Does this answer your question? [How do I check if an element is hidden in jQuery?](https://stackoverflow.com/questions/178325/how-do-i-check-if-an-element-is-hidden-in-jquery) – Manas Khandelwal Apr 08 '21 at 23:51

1 Answers1

1

I'd tried you code here, and it works.

  • what only i changed is just remove one ')'( maybe you alreay knew )
    if($('#discountbox').is(':visible')))

to

    if($('#discountbox').is(':visible'))