JQuery fading a div after a certain time

Here’s a handy bit of code that i use quite regularly, its particularly useful if your getting a response message from a form to notify the user that there data was sent, or comunicate an error and you want to fade the message out after a set time.
Firstly you need to include the jQuery framework you can download the latest version here.
All you need to change is the target div, in our case ‘mydiv’
$(document).ready(function(){
setTimeout(function(){
$("div.mydiv").fadeOut("slow", function () {
$("div.mydiv").remove();
});
}, 2000);
});
To adjust the amount of time until the fade function is triggered simply change the ‘2000′ to a different number, currently set at 2 seconds or 2000 milliseconds.

Hey cool this is like a behind the scenes of DDC lol I if I needed this I sure would use it lol
Ha, yeah subscribe to my feed and get the inside gossip!
Nice piece of information to get me started! Think it’ll come in handy when confirming, for example, a save when using AJAX.
Great tip, been looking for something like this for a long, long time.
Good work
Excellent job!
EXACTLY what i needed.
Leave a comment...
Connect
Latest Poll
Recent Posts
Design & Dev Jobs
Full-time and freelance job opportunities available at Authentic Jobs:
Post a job and reach web professionals everywhere.