Javascript events/functions triggering not only from button, but from whole page, incremental game -


i'm trying make own little incremental game , have few buttons currently. buttons following:

  • "ka-ching" - money clicking
  • 3 buttons buying "autoclickers".

my problem autoclickers 2 , 3 bought when enough money when click anywhere on site, "ka-ching" button. stopped happening ka-ching when using kaching(ev) {ev.stoppropagation();}; doesn't work others.

my full code: https://jsfiddle.net/veix/sdh94o6m/19/ (interval doesn't work in jsfiddle reason, doesn't matter, isn't bug i'm having. jsfiddle doesn't have stoppropagation(); in question.

also part of problematic parts (i think):

//function buying hotdog function buyhd() {     if (buyclicker(hotdog.cost, this)) {         hotdog.clicks += 0.10;         hotdog.cost *=hotdog.costincrease;         hotdog.level++;          var e = document.getelementbyid("hotdog-level");         e.innerhtml = "lvl " + hotdog.level;          var e2 = document.getelementbyid("buyhotdog");         e2.innerhtml = "buy " + hotdog.cost.tofixed(2) + " dollors";     }; }; 

and

//event listener buying hotdog var elhd = document.getelementbyid("buyhotdog"); elhd = addeventlistener("click", buyhd, false); 

how can stop events triggering clicking anywhere? somehow doesn't happen 1st autoclicker button.

you have use addeventlistener on element want have click event.

so try elhd.addeventlistener("click", buyhd, false);


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -