javascript - Why is this jQuery click function not working? -


code:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script type="text/javascript">     $("#clicker").click(function () {         alert("hello!");         $(".hide_div").hide();     }); </script> 

the above code doesn't work. when click on #clicker, doesn't alert , and doesn't hide. checked console , no errors. checked see if jquery loading , indeed is. not sure issue is. did document ready function alert , worked not sure doing wrong. please help. thanks!

you supposed add javascript code in $(document).ready(function() {}); block.

i.e.

$(document).ready(function() {   $("#clicker").click(function () {     alert("hello!");     $(".hide_div").hide();   }); }); 

as jquery documentation states: "a page can't manipulated safely until document "ready." jquery detects state of readiness you. code included inside $( document ).ready() run once page document object model (dom) ready javascript code execute"


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -