I know this is a known issue, and I've tried the stopPropagation
solution. It doesn't work. I'm baffled as to why this would happen anyway (I don't understand why it should). Anyway, here is the code.
I have a jQM button:
<a href="#" id="glossary_option1" class="ui-btn ui-btn-right ui-btn-icon-notext ui-nodisc-icon ui-alt-icon">No text</a>
And I use this code to toggle it on and off:
$("#glossary_option2").click(function(){
toggleGlos();
});
This calls this function, which will eventually also be called by glossary_option2, 3 and 4 (hence me having the function)
function toggleGlos() {
if (localStorage.glossaryopt === "off") {
$("#glossary_option1").removeClass("ui-icon-nobook").addClass("ui-icon-book");
$("#glossary_option2").removeClass("ui-icon-nobook").addClass("ui-icon-book");
$("#glossary_option3").removeClass("ui-icon-nobook").addClass("ui-icon-book");
$("#glossary_option4").removeClass("ui-icon-nobook").addClass("ui-icon-book");
console.log(localStorage.glossaryopt);
localStorage.glossaryopt = "on";
$(".glossaryLink").css({
"color": "white",
"background-color": "#CC8DCC",
"border": "1px solid white",
"padding": "0px 4px",
"font-size": "0.9em"
});
} else {
localStorage.glossaryopt = "off";
$("#glossary_option1").removeClass("ui-icon-book").addClass("ui-icon-nobook");
$("#glossary_option2").removeClass("ui-icon-book").addClass("ui-icon-nobook");
$("#glossary_option3").removeClass("ui-icon-book").addClass("ui-icon-nobook");
$("#glossary_option4").removeClass("ui-icon-book").addClass("ui-icon-nobook");
console.log(localStorage.glossaryopt);
$(".glossaryLink").css({
"color": "black",
"background-color": "white",
"border": "none",
"padding": "0",
"font-size": "1em"
});
}
}
Every time I click the button both parts of this function fire. glossaryopt is turned on then off, as shown by the console log.
I know this is a known issue but a. I can't fix it and b. I've done exactly this kind of thing many, many times. Why is it not working now?