My javascript is not working (w jquery as well) -


i not able javascript work html:

<div id="tomato">     <body>         <button id="totato">total</button>     </body> </div> 

javascript:

$(document).ready(function() {   $("totato").click = potato();    function potato() {     $("tomato").css("background", "red");   } }) 

you missing #=> id selector

event binding should implement using .on() expect first argument event , second argument function expression(callback function)

note have parenthesis() around function name invoke function when line executed.

$(document).ready(function() {    $("#totato").on('click', potato);      function potato() {      $(this).css("background", "red");    }  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <div id="tomato">      <body>      <button id="totato">total</button>    </body>  </div>

or

use .click() expect argument function expression(callback function)

$(document).ready(function() {    $("#totato").click(potato);      function potato() {      $(this).css("background", "red");    }  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <div id="tomato">      <body>      <button id="totato">total</button>    </body>  </div>


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -