Paul Paul - 3 months ago 9
Javascript Question

event click firing on page load

beginner question with javaScript and jQuery. I can post the html if necessary. I have a div with an id of "container" that when clicked should make a text div with id of "text" appear. So my javaScript code so far:

$(document).ready(function (){
$("#container").click($("#text").fadeIn(500));
});


The problem is that the fading happens when the page loads. Can someone explain why? Many thanks,

David

Answer

Pass function to click:

$(document).ready(function (){
   $("#container").click(function() { $("#text").fadeIn(500) } );
});