I have a autoclick script which is working with javascript. But it is working only with ID. I need to add it multiple section of page. I tried getElementsByClassName
and getElementByClassName
. But it was failed. Please convert it from ID to class name.
Not Working with Class
<a href="https://www.google.com" class="hello-btn" target="blank">Google</a>
<script>
var helloBtn = document.getElementByClassName("hello-btn");
helloBtn.addEventListener("click", () => {
console.log("Btn clicked");
});
var interval = window.setInterval(() => {
helloBtn.click();
}, 4000);
</script>
Working with Class
<a href="https://www.google.com" id="hello-btn" target="blank">Google</a>
<script>
var helloBtn = document.getElementById("hello-btn");
helloBtn.addEventListener("click", () => {
console.log("Btn clicked");
});
var interval = window.setInterval(() => {
helloBtn.click();
}, 4000);
</script>