How to create a timer to run an HTML click 'class'
So I am very new to JS and I have been messing around with a template file. I have been lucky so far in searching and finding most of my issues, but I don't think I know exactly what to search for in this issue.
Here it is:
There is a picture, that when clicked, runs part of a JS file that changes the background on the website.
the class 'next' is what changes the image. How can I go about creating a timer in my HTML page that will automatically "click" this every 20 seconds. Keeping the actual physical click functionality of the images alive, as well.
Ultimately, I want the background to change by itself if the user does not click on the image, every 20 seconds.
I do not think it is a great problem, though I am not sure I understand it correctly.
To perform a software click you need to find an element with JS (for which I recommend adding of "id=..." attribute to link element) and call .click() on it. If you just want to change its class, you can do it without click either.
Setting up timer for clicking looks like:
Code:
setInterval(myClick, 20000);
function myClick() {
document.getElementById("myLink").click();
} // myClick
Remember to add id "myLink" to the link (or something like this) - id-s are usually used especially for simplifying searching for html element inside a script (though there are other options).
Bookmarks