I am working with this specific div:
<div class="signs" id="signs" onclick="toggle()">+</div>
It currently displays the positive sign. I have set up a JavaScript function that is triggered when the div is clicked to change it to a negative sign using HTML code −
:
function toggle() {
var x = document.getElementById("signs");
if (x.textContent === `+`) {
x.textContent = `−`;
} else {
x.textContent = `+`;
}
}
The issue I am facing is that the toggle
function is converting the positive sign to plain text −
instead of displaying the actual negative sign! How can I modify my JavaScript structure to successfully switch from the positive sign to the negative sign upon clicking?