How to create accordion on blogger using HTML & JavaScript ?

Create accordion using html & javascript on blogger. Its too much easy to create accordion using html & javascript .  Below is the code by using you create an accordion on blogger using html & javascript.

HTML


<button class="acc">Show Answer</button>

<div class="pnl">

<p></p>

</div>

CSS


.acc {
  background-color: #eee;
  color: #444;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
  transition: 0.4s;
}
.active, .acc:hover {
  background-color: #ccc; 
} 
.pnl {
  padding: 0 18px;
  display: none;
  background-color: white;
  overflow: hidden;
}

JavaScript


<script type='text/javascript'>

//<![CDATA[
var acc = document.getElementsByClassName("acc");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var pnl = this.nextElementSibling;
if (pnl.style.display === "block") {
pnl.style.display = "none";
} else {
pnl.style.display = "block"; }
});
}
//]]>
</script>

If you have any question regarding to create accordion using html & JavaScript you can ask questions on our support forum.

How to create accordion on blogger using HTML & JavaScript ?

Published on 25-Sep-2021 0:25:12

You may also like this!