Using Javascript to define button actions
HI all,
I have adobe acrobat dc pro. I have a document that I want to add a button that opens an accordion like paragraph below it. Adobe does not give any error codes on the code, which is html, css, and javascript combined. However, when the button is clicked, nothing happens. I created another button on the same page to open google and it works so i know it s not an error in the button function overall. Here is the code I am trying to use. I have tried creating a document javascript, and a action javascript and nothing seems to work. Any help would be greatly appreciated! My overall plan is to try and code into the document an accordion function, since it is not built in.
<script>
<div id="accordion">
<div class="panel active"> <!-- first panel -->
<div class="acc-header">header1</div>
<div class="acc-body">body of panel 1</div>
</div>
<div class="panel"> <!-- second panel -->
<div class="acc-header">header2</div>
<div class="acc-body">body of panel 2</div>
</div>
<div class="panel"> <!-- third panel -->
<div class="acc-header">header3</div>
<div class="acc-body">body of panel 3</div>
</div>
</div>
function initAccordion(accordionElem){
//when panel is clicked, handlePanelClick is called.
function handlePanelClick(event){
showPanel(event.currentTarget);
}
//Hide currentPanel and show new panel.
function showPanel(panel){
//Hide current one. First time it will be null.
var expandedPanel = accordionElem.querySelector(".active");
if (expandedPanel){
expandedPanel.classList.remove("active");
}
//Show new one
panel.classList.add("active");
}
var allPanelElems = accordionElem.querySelectorAll(".panel");
for (var i = 0, len = allPanelElems.length; i < len; i++){
allPanelElems.addEventListener("click", handlePanelClick);
}
//By Default Show first panel
showPanel(allPanelElems[0])
}
initAccordion(document.getElementById("accordion"));
</script>
