I've been messing around with making some simple chrome extensions, and everything was going smooth, editing html on a web page with some javascript is pretty straight forward. Now the problem starts when i want to add some javascript functions, for example to toggle a certain div etc. Here is my code
{
"name":"Warmane",
"description":"Some modifications to warmane forum.",
"version":"1.2",
"manifest_version":2,
"content_scripts": [
{
"matches": ["http://forum.warmane.com/*"],
"js": ["myscript.js"]
}
]
}
content script
//Creating Elements
//Adding lates post button
var nodeLi = document.createElement("LI");
nodeLi.setAttribute("id", "latest_news");
var nodeA = document.createElement("A");
var content = document.createTextNode("Latest posts");
nodeA.appendChild(content);
nodeA.setAttribute("class", "navtab");
nodeA.setAttribute("href", "http://forum.warmane.com/search.php?do=getnew");
//Adding mod cp button
var nodeLiTwo = document.createElement("LI");
nodeLiTwo.setAttribute("id", "mod_cp");
var nodeATwo = document.createElement("A");
var contentTwo = document.createTextNode("Mod Cp");
nodeATwo.appendChild(contentTwo);
nodeATwo.setAttribute("class", "navtab");
nodeATwo.setAttribute("href", "http://forum.warmane.com/modcp/");
//latest posts
document.getElementById("navtabs").appendChild(nodeLi);
document.getElementById("latest_news").appendChild(nodeA);
//mod cp
document.getElementById("navtabs").appendChild(nodeLiTwo);
document.getElementById("mod_cp").appendChild(nodeATwo);
//Editing style
document.getElementById("page-frame").setAttribute("style", "display: none");
document.getElementsByClassName("above_body")[0].setAttribute("style", "top: 170px");
document.getElementsByClassName("navigation-wrapper")[0].setAttribute("style", "top: 90px");
Now on this web page i want to edit i have a div
<p class="toggle">Toggle</p>
<div id="someDiv"></div>
which i want to show/hide every time i click on that <p>, and i have no idea how can i do that. Can anyone explain to me how can i go about this?
addEventListener?