Why is the click function not called?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" type="text/javascript" />
<script type="text/javascript">
$('#test').click(function () {
alert('clicked');
});
</script>
</head>
<body>
<a id="test" href="#">Click here</a>
</body>
</html>
You are adding an event to an element that doesn't exist yet. Wrap your event listener in a DOM-ready function or move your script tag below the element.
you must have a closing script tag at:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"
type="text/javascript" >
</script>
and you must call your click binding in:
$(document).ready(function(){
$('#test').click(function () {
alert('clicked');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With