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.");     }); }); 

updated fiddle


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -