Home

WayneCarl Barker's Portfolio/ Blog

Go Back

Show more button Jquery code

WayneCarl

September 22, 2022

Show more…

If you have to much text to show you can hide some of it and show when the user clicks show more

let readMoreText = $(".read-more-text")[0];
const text = $(".text-to-show")[0];

$(readMoreText).click(() => {
  text.classList.toggle("hide");
  if (readMoreText.innerText === "show more...") {
    readMoreText.innerText = "show less";
  } else {
    readMoreText.innerText = "show more...";
  }
});