Here’s my javascript code for a "see more" button. How can I also make it disappear on click?
function myFunction() {
var x = document.getElementById("dsec");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "block";
}
}
</script>
>Solution :
You will need to give your button an Id and do the same thing you are doing for your description block.
ie:
function myFunction() {
var x = document.getElementById("dsec");
var btn= document.getElementById("btn");
if (x.style.display === "none") {
x.style.display = "block";
btn.style.display = "none";
} else {
x.style.display = "none";
btn.style.display = "block";
}
}
</script>
… or similar. I’m not entirely sure what is triggering your ‘myFunction’ or your references… but the concept is there.
In the future, it’d be worthwhile to add a little more context and spell-check your code to make it easier to help.
I will also note @Scott Marcus suggestion of using actual styles instead of inlining stuff is the better overall technique.