Dashboards & Visualizations

Why is my Javascript code not working?

Anmar0293
Path Finder
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.accordion {
    background-color: #002B51;
    color: white;
    cursor: pointer;
    padding: 18px;
    width: 40%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 15px;
    transition: 0.4s;
}

.active, .accordion:hover {
    background-color: #2d8dd5;
}

.accordion:after {
    content: '\002B';
    color: white;
    font-weight: bold;
    float: right;
    margin-left: 5px;

}

.active:after {
    content: "\2212";

}

.panel {
    padding: 0 18px;
    background-color: silver;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
width: 35.7%
}


</style>
</head>
<body>




<button class="accordion">Lifecycle Hygiene

</button>
<div class="panel">
  <p>Lifecycle Hygiene </p>
</div>



<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}
</script>

</body>
</html>

Everything is fine, except the list should by dropped down by the Jquary code on the script section. not sure why id doesn't get executed.

0 Karma

mstjohn_splunk
Splunk Employee
Splunk Employee

Hi @Anmar0293! Would you mind giving us a little bit more info about this problem? For example, what are you trying to do with this JS code,etc... That way, users who are having a similar issue could learn from this thread.

Thanks and happy Splunking!

0 Karma

Anmar0293
Path Finder

@mstjohn,

Thank you for replying to me. I have solved the issue. thank you!

0 Karma

mstjohn_splunk
Splunk Employee
Splunk Employee

Hi @anmar0293, Great, I'm glad you figured it out! Would you mind posting an explanation for how you solved your problem below? It would be great to pass on that knowledge to other users who may be having a similar issue. Thanks!

0 Karma
Get Updates on the Splunk Community!

Pro Tips for First-Time .conf Attendees: Advice from SplunkTrust

Heading to your first .Conf? You’re in for an unforgettable ride — learning, networking, swag collecting, ...

Raise Your Skills at the .conf25 Builder Bar: Your Splunk Developer Destination

Calling all Splunk developers, custom SPL builders, dashboarders, and Splunkbase app creators – the Builder ...

Hunt Smarter, Not Harder: Discover New SPL “Recipes” in Our Threat Hunting Webinar

Are you ready to take your threat hunting skills to the next level? As Splunk community members, you know the ...