javascript - <script> Help on .click() -


i got coding , decided mess around before started coding more in-depth. trying make simple game click object, little animation , adds 1 counter.

i have animation executed, lost how make counter. trying use .js via tags, because website never loads script.js file, though reference properly.

anyways here html code:

<!doctype html> <html> <head>     <link rel="stylesheet" href="style.css" />     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> </head>  <body>     <h3>0 clicks</h3>     <img id="choco" src="http://cdn.shopify.com/s/files/1/0210/5354/products/chocolate_chip_no_background_1_medium.png?v=1365686508">     <img id="whirl" src="whirl.jpg" style="width:25em; height:25em;"> </body> <script>     $(document).ready(function() {     ('#cookie').click(function() {         function toclick(clicks){             return (clicks + 1);         print clicks;         };     }); }); </script> </html> 

my messy, trying plethora of options try , work doesn't.

so trying do, everytime click object want add 1 counter have on page.

0 clicks

i not sure that's possible hope out there can me out :)

thanks!

    $(document).ready(function() {         $('#cookie').click(function() {            incrementcount();         });     });    function incrementcounter() {           var previouscounter = parseint($("#counter").text());           previouscounter = isnan(previouscounter) ? 0: ++previouscounter;            $("#counter").text(previouscounter);   }    function resetcounter() {      $("#counter").text(0);  } 

change html

<body>     <h3><span id="counter">0</span> clicks</h3> 

the above code after if don't specify 0 span. have given bonus function - resetcounter :)


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -