I'm working on this project where I want to add some html on my wordpress website. The point is to add a "read more" button. Here's the code:
<p>some text<span id="dots">...</span><span id="more">Some more text.</span></p>
<button onclick="myFunction()" id="myBtn">Read more</button>
<style>
#more {display: none;}
</style>
<script type="text/javascript">
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
</script>
Here's the result:
Read more #more {display: none;} function myFunction() { var dots = document.getElementById(“dots”); var moreText = document.getElementById(“more”); var btnText = document.getElementById(“myBtn”); if (dots.style.display === “none”) { dots.style.display = “inline”; btnText.innerHTML = “Read more”; moreText.style.display = “none”; } else { dots.style.display = “none”; btnText.innerHTML = “Read less”; moreText.style.display = “inline”; } }
My issue: the wordpress reads the and processes the html, but spits back the javascript (exactly as stated above).
Please help