javascript - $.on() performs multiple times. Why? -
i discovered strange thing in code:
drawing.activeobjects = new array(); $(".svgobjects").on("mousedown", function(){ console.log("clicked" + $(this).attr('id')); drawing.activeobjects.push(findobjinarray($(this).attr('id'))); console.log("ao: " + json.stringify(drawing.activeobjects)); });
when click on object 1 time, ok. when click again runs 2 times. , after 7 clicks, can see 7 times "clicked" in console , 7 objects in array.
i don't know why. have 1 object on site, , clear array before check clicks. yet see many objects in array number of clicks make.
the code not magically know want listen 1 click on element , no more. need program behaves way.
if expect called 1 time, need remove code click or can @ jquery's one()
Comments
Post a Comment