I have two files one is the javascript and one is the HTML. and I want to show and hide an element but when I try this its won't work. Also, I use the latest JQuery and a chrome extension I also tried the inner HTML method and nothing.
function updateLabel() {
var x = true; // this is for the localstorage anternative
if (x //localStorage.getItem("EnabledAllSites")) {
$("#toggle").hide(0);
$("#toggle_check").show(0);
x = false; // this is for the localstorage anternative
} else {
$("#toggle").show(0);
$("#toggle_check").hide(0);
}
}
updateLabel();
function toggle() {
/*var background = chrome.extension.getBackgroundPage();
localStorage.setItem("EnabledAllSites", /* this is a boolean*///!background.enabled);
updateLabel();
/*chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.update(tabs[0].id, { url: tabs[0].url });
});*/
}
$("#toggle").click(function () {
toggle();
});
$("#toggle_check").click(function () {
toggle();
});
<body>
<header style="display: flex; justify-content: space-between">
<!--- this is what i want to hide and show --->
<button
style="
background-color: none;
border: none;
width: 42px;
font-size: 18px;
"
id="toggle_check"
>
<div>✅</div>
</button>
<!--- this is what i want to hide and show --->
<button
style="
background-color: none;
border: none;
width: 42px;
font-size: 18px;
"
id="toggle"
>
<div>❌</div>
</button>
</header>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="./popup.js"></script>