I am trying to write a user script that will hide certain elements from a page. The problem is the elements do not appear until a few seconds after the page has loaded, so I am trying to do it with a few seconds of delay.
This is the code I have:
function hide_stuff()
{
var e = document.getElementsByClassName("tab");
if(e)
alert("got elements");
else
alert("didn't get elements");
for( var i = 0; i < e.length; i++){
if (!e[i].id)
e[i].style.display = "hidden";
}
}
setTimeout(hide_stuff(), 5000);
The problem is it doesn't delay at all. The "got elements" alert (which I added as a debugging aid), fires immediately when the page loads. I can't see what I'm doing wrong, although I'm sure it's probably something obvious.
Any help?
The problem is the elements do not appear until a few seconds after the page has loaded, are you using the window.onload event and running your code from there? Rarely is an arbitrary delay to let things load the right thing to do.