While this thread may be old, I recently came across the same issue and found a solution that works perfectly without any console errors or warnings. When you're "inlining" JavaScript code like the example below, there's no need to include "function xx()". Take a look at the following snippet:
Here's a simple solution I wanted to share:
<a href="#" type="button" onClick="var myDiv = document.getElementById('myDIV'); if (myDiv.style.display === 'block') { myDiv.style.display = 'none'; } else { myDiv.style.display = 'block'; }">click</a>
In a standard HTML setup, the same functionality can be achieved with the following implementation of inlined JavaScript:
<body>
<a href="#" type="button" onclick="myFunction()">Try it</a>
...(the rest of the HTML content)....
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
</body>