DHTMLX Docs & Samples Explorer

Adding Items

Item Text
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;">
Item Text <input id="newText" type="text" value="Second Item"> <input type="button" value="Add Item" onclick="addItem();">
</div>
<script>
var id = 0;
var dhxAccord;
function doOnLoad() {
    dhxAccord = new dhtmlXAccordion("accordObj");
    dhxAccord.addItem("a" + (id++), "First Item");
}
function addItem() {
    if (id > 5) {
        alert("Too many items");
        return;
    }
    dhxAccord.addItem("a" + (id++), document.getElementById("newText").value);
}
</script>