0

Im kinda new here in the developer community and cannot find the answer to my question unfortunately, even though I was looking for it for hours.

So the main issue is, that I want to have a "Show more" button in a text, which was working fine with getElementById by it's not working with ClassName.

Could you please help me?

Here is the code:

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, <span class="dots">...</span><span class="more"> quis nostrud exercitation ullamco laboris nisi ut aliquip.</p></span>
<button onclick="myFunction()" class="myBtn">Show more</button>

JS:

function myFunction() {
var dots = document.getElementsByClassName("dots");
var moreText = document.getElementsByClassName("more");
var btnText = document.getElementsByClassName("myBtn");

if (dots.style.display === "none") {
  dots.style.display = "inline";
  btnText.innerHTML = "Show more";
  moreText.style.display = "none";
}
else {
  dots.style.display = "none";
  btnText.innerHTML = "Show less";
  moreText.style.display = "inline";
}

}

Thanks in advance for your feedback.

0 Answers0