javascript - addEventListener() click incorrectly executing -
i'm new javascript, , made small game using prompts. in process of building ui , phasing out prompts. @ moment have main menu, , fight menu. pressing fight takes fight menu list of moves. after pressing "ora" in fight menu supposed bring prompt stating attack , bringing main menu.
while happen, when brought main menu acts if still in attack menu.
document.getelementbyid("fight") var fightmenu = fight.addeventlistener("click", fightmenufunction) function fightmenufunction() { document.getelementbyid("fight").id = "ora"; document.getelementbyid("ora").innerhtml = "<p class='textstuff'>ora</p>"; document.getelementbyid("status").id = "get_angry"; document.getelementbyid("get_angry").innerhtml = "<p class='textstuff'>get angry</p>"; document.getelementbyid("blank1").id = "yell_dio"; document.getelementbyid("yell_dio").innerhtml = "<p class='textstuff'>yell dio</p>"; document.getelementbyid("blank2").innerhtml = "<p class='textstuff'></p>"; var menureturn = function() { document.getelementbyid("ora").id = "fight"; document.getelementbyid("fight").innerhtml = "<p class='textstuff'>fight</p>"; document.getelementbyid("get_angry").id = "status"; document.getelementbyid("status").innerhtml = "<p class='textstuff'>status</p>" document.getelementbyid("yell_dio").id = "blank1"; document.getelementbyid("blank1").innerhtml = "<p class='textstuff'>blank1</p>" document.getelementbyid("blank2").innerhtml = "<p class='textstuff'>blank2</p>" } document.getelementbyid("ora").addeventlistener("click", function() { menureturn(); var oraoraattack = math.random(); if (oraoraattack >= 0.4 && buff == 0) { allyattackdamage(20); } else if (oraoraattack >= 0.4 && buff >= 1) { allyattackdamage(40); } else { confirm("your attack missed!") enemybattlesystem(); } }); document.getelementbyid("get_angry").addeventlistener("click", function() { confirm("it works!"); }); document.getelementbyid("yell_dio").addeventlistener("click", function() { confirm("it works!"); }); }
from
function fightmenufunction() { document.getelementbyid("fight").id = "ora";
and
var menureturn = function() { document.getelementbyid("ora").id = "fight";
we can see using same element whole time, unless clear event listeners trigger them, no matter current id is. (as event bound element, not id)
you should using 2 elements though.
Comments
Post a Comment