I'd like to show/hide text...I understand the minimum basics of Manifest 2 and have successfully implemented a javascript dropdown menu that uses an eventlistener...
This simple code works when I open popup.html in Google as a website. It doesn't work in the actual extension (clicking the logo).
I think I need a listener or similar for security reasons...but don't know how to make it work.
The goal is to be able to show/hide blocks of text visible in the popup.html page that appears when you click the extension's logo/button in Chrome. Any help deeply appreciated...
HTML:
<a id="displayText" href="javascript:toggle();">show</a> <== click Here
<div id="toggleText" style="display: none"><h1>Hello world</h1></div>
JS:
function toggle() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "show";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
}
Update after question:
Thanks so much for responding...
It's a very straightforward Extension...yes, three files: manifest.json, popup.html and popup.js.
The popup shows when you click the icon - everything works great except the little bit of javascript to make show/hide work.
I don't get an error - it just doesn't work (maybe there's a way to see errors?). I think the security model is stopping the js from running.
The same thing happened with the simple drop-down menu, but I got around it by adding listeners to the js file. The example below WORKS for the jump menus...so I'm puzzling over how to allow the simple js in the show/hide code to work.
Function init() {
jump = document.getElementById('jumpchoice');
jumpowl = document.getElementById('jumpchoiceowl');
jumpmla = document.getElementById('jumpchoicemla');
jumpapa = document.getElementById('jumpchoiceapa');
jump.addEventListener('change',jumpto,false);
jumpowl.addEventListener('change',jumptoowl,false);
jumpmla.addEventListener('change',jumptomla,false);
jumpapa.addEventListener('change',jumptoapa,false);
}
document.addEventListener('DOMContentLoaded', init);