Akash Akash - 3 years ago 150
jQuery Question

$ not found error while using setinterval

I am trying to automatically click a button when it is created and after clicking the button, close the interval. But the following script is giving me

$ is not defined
error. Can anyone help me where am I doing wrong?

var timer = setInterval(
function () {
if ($('#element')) {
$('#element').click();
clearInterval(timer);
}
else
{
console.log('Element not found');
}
}, 1000);

Answer Source

only if you are using jQuery add their cdn in your html page

<script
  src="https://code.jquery.com/jquery-2.2.4.js"
  integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
  crossorigin="anonymous"></script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download