javascript - jQuery click function not working on IDs -
i'm trying jquery things when click div. i've given id (ghost) , when load page , click it, nothing happens. if change script "#ghost" "html" script works. what's wrong syntax here?
jsfiddle: https://jsfiddle.net/vl78vr5m/
<body> <div class = "graveyard"> <div id="cont"> <div id="ghost"> <div class="eye"></div> <div class="eye"></div> <div id="tickle"></div> </div> </div> </div>
js:
alert("does work?"); $('#ghost').click(function(){ alert("the paragraph clicked."); });
you forgot load jquery in jsfiddle.
adding works:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
it practice make functions work first when page loaded. can accomplish wrapping in $(function() { .. });
, this:
$(function() { $('#ghost').click(function(){ alert("the paragraph clicked."); }); });
Comments
Post a Comment