javascript - Why is this method called multiple times? -
when refresh page, must click button twice in order prompt. after that, each time click same button , call classichover() method (without refreshing), 1 plus prompt(two prompts, 3 prompts, four...).
this code:
function classichover(){ $('#button1').click(function(){ gridsize = prompt("set grid size") $('.container').empty(); for(i = 0; < gridsize * gridsize; i++) { $('.container').append("<div>a</div>"); }; }); };
button:
<input id="button1" type="button" value="set new grid" onclick="classichover()" />
what doing wrong? js/jquery newbie btw
your click calls classichover
. classichover
adds function button's listener. each time click it, add listener. first click adds 1. second click runs 1 , adds another. third click runs 2 , adds another. repeat each click.
Comments
Post a Comment