Skip to content

Perform Function when Element ID is Visible

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:


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

Unfortunately, this does not appear to be working.


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

  • what only i changed is just remove one ‘)'( maybe you alreay knew )