I am having an issue where I cannot swap my images for a element. I can do it by actually changing the background-image css tag, but I want to swap the class based on the state of my game.
I have 7 .gif images for the various states of the game.
The HTML is initalized and set to level zero image and will load the proper image as the level class is also part of the
container element.
The js code to do the swap is the setHangLvl method:
In the debugger, I see the class added, but the but the old class still remains. Here is a screen shot of the window:
I did a push of my code at this point.
the github url to my repository is here
Any help would be appreciated. Thanks, Mike
I tried the "()" and It still did not work, then I simplified the method so it would be easier to debug and step through it with the debugger. That led me to find out that the operator precedence was correct and did not need the parens. But it led me to find out I had misspelled the class name.
Thank you for the reply!
This issue is now solved but it opened up another one that I can find out. The issue was a typo where the class defined had a "-" and I was using an "_" underscore to change it. I don't know how many times I looked at it but getting away for a few hours then coming back opened my eyes. The bigger problem I have is I made an assumption that the class I need to remove is lvl-1 which is true but in my testing where I send in levels not in sequence or perhaps a reset of the game where we go back to zero it won't be true. for now I will just make a circular assumption that the states of the game go in order from 0-6 then when we go to reset the game we can set it back to zero and delete six. Probably better would be to find out what classes the element has and just delete it if I can figure that out.
I am having an issue where I cannot swap my images for a element. I can do it by actually changing the background-image css tag, but I want to swap the class based on the state of my game. I have 7 .gif images for the various states of the game.
The HTML is initalized and set to level zero image and will load the proper image as the level class is also part of the
The js code to do the swap is the setHangLvl method:
In the debugger, I see the class added, but the but the old class still remains. Here is a screen shot of the window:
I did a push of my code at this point.
the github url to my repository is here Any help would be appreciated. Thanks, Mike
Does anything change if, in
.removeClass
, you wraplvl-1
in parentheses? Wondering if it could be an order of operations issue.I tried the "()" and It still did not work, then I simplified the method so it would be easier to debug and step through it with the debugger. That led me to find out that the operator precedence was correct and did not need the parens. But it led me to find out I had misspelled the class name. Thank you for the reply! This issue is now solved but it opened up another one that I can find out. The issue was a typo where the class defined had a "-" and I was using an "_" underscore to change it. I don't know how many times I looked at it but getting away for a few hours then coming back opened my eyes. The bigger problem I have is I made an assumption that the class I need to remove is lvl-1 which is true but in my testing where I send in levels not in sequence or perhaps a reset of the game where we go back to zero it won't be true. for now I will just make a circular assumption that the states of the game go in order from 0-6 then when we go to reset the game we can set it back to zero and delete six. Probably better would be to find out what classes the element has and just delete it if I can figure that out.