/    Sign up×
Community /Pin to ProfileBookmark

Displaying a div for a certain amount of time

If I wanted a div to show for a particular amount of time (say 5 secs) and then disappear (display:none; will work), how would I go about doing it? Would this be better executed in JS or will php do the job just as well?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Jarrod1937Nov 03.2010 — Php is a server side language. Once the output is sent from it, you can't change it, unless you are using a client side language like javascript. So, yes, javascript would be your best/only choice here. You can probaby just do something like:

document.getElementById('divid').style.display='none';

executed on a timer. For the timer you can use something the setTimeout method:

http://www.w3schools.com/js/js_timing.asp

Edit: Quick note, but be sure to be careful, design it so that user agents without javascript support don't just see a big div in their way (unless that is your intention).
Copy linkTweet thisAlerts:
@BelrickNov 07.2010 — PHP has no timing (can be put to sleep but not the same thing!).

however you can use setTimeout to call a Ajax function if PHP is doing all your page display.
×

Success!

Help @bradleybebad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...