I did a simple HTML page which has JavaScript as following:
<script>
function myFunction() {
var y = document.querySelector('input[name="mum1"]:checked').value;
var z = document.querySelector('input[name="num2"]:checked').value;
var x = +y + +z;
document.getElementById("total").innerHTML = x;
}
</script>
<button onclick="myFunction()">Try it</button>
It works fine by itself. When I add it to a WordPress website(add HTML in a page). The error message comes like this:
Uncaught SyntaxError: Unexpected token
Uncaught ReferenceError: myFunction is not defined
I guess this cause by JavaScript conflict, my WordPress website use jquery.
How to solve the problem.