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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -