Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS "Read More / Read Less" Button Text not working on Initial Page Load

Hi, I'm trying to do a Read More/Read Less style button with a translation of the text on our webpage: https://thenewgallery.org/The-New-New-Society-Ang-Bagong-Bagong-Lipunan-Cris-Mora

The button works, however the text within the button that reads "中文翻译 Chinese Translation" does not load unless you click on the button first. I would like this text to show automatically when you load the page, instead of an empty button. I've been trouble shooting this and I have been unable to figure it out. Below is my HTML code and CSS code for the button.



HTML:
<p>中文翻译 Chinese Translation<span id="dots" 
style="display: inline;">...</span><br><br>
<span id="more" style="display: none;">
<br><br>
CHINESE TRANSLATION TEXT GOES HERE
<br><br>
</span></p>
<button onclick="myFunction()" id="myBtn"></button>

<script>
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 = "中文翻译 Chinese Translation";
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "隐藏中文翻译 Hide Chinese Translation";
    moreText.style.display = "inline";
  }
}
</script>

CSS:
input,
button {
  color: rgba(11, 0, 255, 0.81);
  font-family: Raleway;
  font-size: 14px;
  padding: 0;
  margin: 0;
  border: 0;
  background-color: #fff;
}
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom