Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to a custom icon to my show less button

function toggleText() {
  var showMoreText = document.getElementById("more");  
  var buttonText = document.querySelector("#moreButton p");
  
  if (startpoint.style.display === "none") {
    showMoreText.style.display = "none";
    startpoint.style.display = "table-cell";
    buttonText.innerHTML = "Show More";    
    buttonText.classList.remove('less')
  } else {
    showMoreText.style.display = "table-cell";
    startpoint.style.display = "none";
    buttonText.innerHTML = "Show Less";
    buttonText.classList.add('less')
  }
}
 .pink{
    color: #FF7B5F;
  }

  #more {
    display: none;
}

  #moreButton{
    background-color:transparent;
    border-color: transparent; 
   }


   .less{
       color: #FF7B5F;
   }
   
   .more{max-width:20px;
   
   }
 <div id="startpoint"></div>
          <div id="more">
          <div class="row">
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/RIZEK.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Sabahoo.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Securite.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/SIP.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Spectar.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/stake.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Standard Chartered.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Step.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Switzgroup.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Tarjama.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/WTTC.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Z&V.jpg" alt="">
            </div>
          </div>
        </div>
        <button onclick="toggleText()" id="moreButton">
         <p class="pink">Show More</p> 
         <img class="more" src="https://e7.pngegg.com/pngimages/325/32/png-clipart-arrow-down-android-down-arrow-hand-desktop-wallpaper-thumbnail.png" alt="">
        </button>
        </div>

I’ve been struggling with java script lately because I’m a noob developer, but I finally got it working by creating a functional java script show more show less button with a custom down arrow logo for show more, but I couldn’t figure out how to have an up arrow for show less, which is annoying. Any help would be greatly appreciated.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Hope that helps:

Select your icon

var moreIcon = document.querySelector("#moreButton img");

Toggle less class in icon.

moreIcon.classList.add('less');
moreIcon.classList.remove('less');

When less class is added, rotate the icon using CSS

img.more.less {
  transform: rotate(180deg);
}

function toggleText() {
  var showMoreText = document.getElementById("more");  
  var buttonText = document.querySelector("#moreButton p");
  var moreIcon = document.querySelector("#moreButton img");
  
  if (startpoint.style.display === "none") {
    showMoreText.style.display = "none";
    startpoint.style.display = "table-cell";
    buttonText.innerHTML = "Show More";    
    buttonText.classList.remove('less');
    moreIcon.classList.remove('less');
  } else {
    showMoreText.style.display = "table-cell";
    startpoint.style.display = "none";
    buttonText.innerHTML = "Show Less";
    buttonText.classList.add('less');
    moreIcon.classList.add('less');
  }
}
.pink{
    color: #FF7B5F;
  }

  #more {
    display: none;
}

  #moreButton{
    background-color:transparent;
    border-color: transparent; 
   }


   .less{
       color: #FF7B5F;
   }
   
   .more{max-width:20px;
   
   }
   
   img.more.less {
     transform: rotate(180deg);
   }
<div id="startpoint"></div>
          <div id="more">
          <div class="row">
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/RIZEK.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Sabahoo.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Securite.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/SIP.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Spectar.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/stake.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Standard Chartered.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Step.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Switzgroup.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Tarjama.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/WTTC.jpg" alt="">
            </div>
            <div class="col-6 col-md-3 col-lg-2">
              <img class="img-fluid" width="250" src="./images/clients/Z&V.jpg" alt="">
            </div>
          </div>
        </div>
        <button onclick="toggleText()" id="moreButton">
         <p class="pink">Show More</p> 
         <img class="more" src="https://e7.pngegg.com/pngimages/325/32/png-clipart-arrow-down-android-down-arrow-hand-desktop-wallpaper-thumbnail.png" alt="">
        </button>
        </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading