Reputation: 59
So I have this Javascript code, however i want to make it execute the code after 5 seconds, i was wondering whether this was possible:
var links = document.querySelectorAll(".feed-item a");
for(var i = 0; i < links.length; i++){
links[i].onclick = function() {
location.href="/mypage.html";
}
}
Upvotes: 1
Views: 57
Reputation: 12864
You're looking for setTimeout
function.
setTimeout
Calls a function or executes a code snippet after a specified delay.
Code
setTimeout(function() {
var links = document.querySelectorAll(".feed-item a");
for (var i = 0; i < links.length; i++) {
links[i].onclick = function() {
location.href = "/mypage.html";
}
}
}, 5000); // delay is the number of milliseconds (5000 = 5sec)
Upvotes: 2