I have found this code for a hide/show ID effect. I am building with Elementor in WP.
<button onclick="myFunction()">show / hide</button>
function myFunction() {
var x = document.getElementById ("showprice");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
This works, but I would like to modify the code to hide/show a Class instead of ID – but changing it to the following doesn’t work. Any tips?
function myFunction() {
var x = document.getElementsByClassName("showprice");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}