...

View Full Version : jQuery binding problems



ProSkt02
11-04-2010, 08:44 AM
hey guys,
i have this code, and i dont know why it doesn't work.
what i want it to do is when the link is clicked a message will be shown inside the div with the "la" id.



<html>
<head>
<title>NoNe</title>

<script type="text/javascript" src="jquery.js"></script>
<script>

var foo=function(e){
e.preventDefault();
$('#la').html('hello world');
};

$('#physics').click(foo);
</script>
</head>
<body>
<div id="la"></div>
<a href="javascript:void(0)" id="physics">Physics Section</a>

</body>
</html>


thanks in adv.

SB65
11-04-2010, 12:56 PM
You need to wrap your click handler within a document ready call:


$(document).ready(function(){
$('#physics').click(foo);
});

ProSkt02
11-04-2010, 03:35 PM
thanks!
i've also noticed that by moving the code-lines after the divs, it works fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum