How to add JavaScript code that I copied from a website in React component and call it using onclick?
this is my code that I copied
function myFunction() {
var hide = document.getElementsByClassName("hide");
var btnText = document.getElementById("myBtn");
if (hide.style.display === "none") {
btnText.innerHTML = "Loadmore";
hide.style.display = "none";
} else {
btnText.innerHTML = "Load less";
hide.style.display = "block";
}
}
I have created a component where I had created a button tag. I want to call the function using onclick. How do I do that?
Aucun commentaire:
Enregistrer un commentaire