javascript - Create an alert on div after third click count -
how can create alert after div being clicked third time? tried examples already, failed on making work.
here's code far (without count part):
$("div").one( "click", function() { $(this).css({ background: "red", cursor: "auto", }); $(this).append( "0" ); $("span").append( "0" ); });
need use javascript keep track of how many times has been clicked.
<button onclick="clicking()>click me</button> var nclicks = 0; var nmaxclicks = 3; function clicking() { // increment counter each time item clicked nclick++; // on 3rd click.... if (nclicks == nmaxclicks){ // enter code thing looking alert("max clicks hit! " + nclicks); } }
Comments
Post a Comment