I'm new in Jquery. I have a problem in my code, i'm very confused that which way is correct when writing jquery code for click event. Please help me and explain thanks in advance !
first method :
<script type="text/javascript">
$('a').click(function(){
alert('you clicked a tag !!! ');
});
</script>
and second method :
<script type="text/javascript">
$(document).ready(function(){
$('a').click(function(){
alert('you clicked a tag !!! ');
});
});
</script>
when i write 2 method for testing, just the second one is successful and display a alert, but the first one do nothing. In addition i review on http://api.jquery.com/click/ the first one is the way they write sample but it run successfully, that make me confused .
<script>
$("p").click(function () {
$(this).slideUp();
});
$("p").hover(function () {
$(this).addClass("hilite");
}, function () {
$(this).removeClass("hilite");
});
</script>