I did check this post
How would i get a button to change a objects opacity with html, js & css
to figure out how to change the opacity of an object with a button. I cannot figure out though how can I customize this code in order to link the opacity of the text to the class or Id of an existing button.
I tried also with
document.getElementsByClassName("pippo1").onclick = function() {myFunction()};
function myFunction() {
document.getElementsByClassName("text1").style.opacity = "1";
}
but it does not work.
I could link the "Change Opacity" button to the text editor I want to custom the opacity, but I could not link an existing button to this Function.
<html>
<script>
function myFunction(button) {
// get data-opacity
let opacity = button.dataset.opacity;
const el1 = document.getElementById("text1");
const el2 = document.getElementById("text2");
const el3 = document.getElementById("text3");
const el4 = document.getElementById("text4");
el1.style.opacity = "1";
el2.style.opacity = "0";
el3.style.opacity = "0";
el4.style.opacity = "0";
}
</script>
</head>
<body>
<button data-opacity="0" class="pippo1" onclick="myFunction(this)">PROJECT</button>
</body>
</html>
Can anyone help?
Thank you
Elena