I have a div which has onclick="myFunction()" for 'Show / hide' id="myTable".
in file.js I use format like this :
function example () {
var popup = '<div class="box">' +
'<div onclick="myFunction()" id="button"></div>' +
'<div id="myTable" class="myTable"></div>' +
'</div>'; //box
}; //End function example()
/**** How to make myFunction () work? ****/
function myFunction() {
var x = document.getElementById("myTable");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}; // End function myFunction()
I want to Show and hide div id myTable using onclick="myFunction()" .
If using html format on w3school, this works.
But I use the .js file format. I cant add the html code other than using the variable
var ex = '<htmlcode></htmlcode>';
[<>]toolbar button; here's how to do one. Without more information, we really can't help you.onxyz-attribute-style event handlers can only call global functions (this is one of several reasons not to use them), so yourmyFunctionhas to be global. Is it?