TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   Magic Div's (http://www.talkphp.com/javascript-ajax-e4x/1683-magic-divs.html)

WinSrev 12-09-2007 05:05 PM

Magic Div's
 
Hey,

I wanted to try and make it so that, if someone clicked a link then it'd wait 3 seconds then make a certain div disappear.

I have this code:
Code:

function hideElement(obj){
    document.getElementById(obj).style.display = "none";
}

And this on the link itself (in an on click):
Code:

window.setTimeout(hideElement(admin2), 3000);
But it just produces an error, as in it does nothing.
Any ideas?
Thanks.

devolio 12-09-2007 05:08 PM

Try setting your window.setTimeout to a var, but I'm curious, what's the error it's giving you?

Also, you may want to just setTimeout, not window.setTimeout.

WinSrev 12-09-2007 05:09 PM

Well, internet explorer gives the error of
Quote:

Originally Posted by IE
Object Required


Wildhoney 12-09-2007 05:09 PM

javascript Code:
function hideElement(obj){
    document.getElementById(obj).style.display = "none";
}

setTimeout("hideElement('admin2')", 3000);

devolio 12-09-2007 05:11 PM

Gah, I thought it was missing quotes too. Shows how much JS I've done lately.

WinSrev 12-09-2007 05:12 PM

That gives a syntax error. It works without the " but it happens instantly.

Salathe 12-09-2007 05:15 PM

JavaScript Code:
setTimeout(function(){ hideElement('admin2'); }, 3000);

devolio 12-09-2007 05:15 PM

Nevermind, I wasn't doing it right and Salathe beat me to it.

Edit: Just in case...

javascript Code:
function hideElement(obj){
    document.getElementById(obj).style.display = "none";
}
function clickTest(){
    window.setTimeout(hideElement('test'), 3000);
}

WinSrev 12-09-2007 05:20 PM

Thanks a lot, it works great :D


All times are GMT. The time now is 12:30 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0