亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

How to change the background color of a button on click/HTML
P粉502608799
P粉502608799 2023-09-08 00:04:48
0
1
649

I made a button similar to "Read More" and when I press it, a text expands down. When the text expands, the button's background changes, and when I press the button again to close the text (e.g. "Read Less"), the button's background returns to its original state. How to implement this function

function myFunction() {
        var dots = document.getElementById("dots");
        var moreText = document.getElementById("more");
        var btnText = document.getElementsByClassName("skillBtn");
      
        if (dots.style.display === "none") {
          dots.style.display = "inline";
          btnText.innerHTML = "閱讀更多";
          moreText.style.display = "none";
        } else {
          dots.style.display = "none";
          btnText.innerHTML = "閱讀更少";
          moreText.style.display = "inline";
        }
      }
#more {display: none;}
<div align="center"><h1 id="skillsid" style="margin-top:10px ;"> 編程語言 <span id="dots"></span> </h1><span id="more">
    這里寫了一些內(nèi)容
    
    <div align="center"><a href="#skillsid"><button class="skillBtn" onclick="myFunction()" ></button></a></div>

P粉502608799
P粉502608799

reply all(1)
P粉348088995

What you are trying to do is called accordion. There is no need to write in JS, because HTML already has <details> and <summary> to implement this function:

#more {
  display: none;
}
<details>
  <summary>編程語言</summary>
  這里寫了一些內(nèi)容
</details>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template