DHTMLX Docs & Samples Explorer

Opening Items

Select Item
Source
<script src="../../codebase/dhtmlxcommon.js"></script>
<script src="../../codebase/dhtmlxaccordion.js"></script>
<link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxaccordion_dhx_skyblue.css">
<script src="../../codebase/dhtmlxcontainer.js"></script>
 
<div id="accordObj" style="position: relative; width: 320px; height: 400px;"></div>
<div style="margin: 50px 0px 20px 0px;">
Select Item <select id="sel"></select> <input type="button" value="Open Item" onclick="openItem();"> <input type="button" value="Close Item" onclick="closeItem();">
</div>
<script>
var sel = document.getElementById("sel");
var dhxAccord;
function doOnLoad() {
    dhxAccord = new dhtmlXAccordion("accordObj");
    dhxAccord.addItem("a1", "a");
    dhxAccord.addItem("a2", "b");
    dhxAccord.addItem("a3", "c");
    dhxAccord.openItem("a1");
    dhxAccord.forEachItem(function(item) {
        sel.options.add(new Option(item.getText(), item.getId()));
    });
}
function getId() {
    var id = sel.options[sel.selectedIndex].value;
    return id;
}
function openItem() {
    dhxAccord.cells(getId()).open();
}
function closeItem() {
    dhxAccord.cells(getId()).close();
}
</script>