DHTMLX Docs & Samples Explorer

### Separator Creation

Position |
Add? |

Source

    <script type="text/javascript" src="../../codebase/dhtmlxcommon.js"></script>
    <script type="text/javascript" src="../../codebase/dhtmlxtoolbar.js"></script>
    <link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxtoolbar_dhx_skyblue.css"></link>

    <div id="toolbarObj"></div>
    <div style="margin-top: 20px;">
    <table cellspacing="0" cellpadding="2" border="0">
        <tr>
            <td style="padding-right: 5px;">Position</td>
            <td><input id="txt1" type="text" value="1" style="width: 30px;"></td>
        </tr>
        <tr>
            <td style="padding-right: 5px;">Add?</td>
            <td><input type="button" value="Add" onclick="add();"></td>
        </tr>
    </table>
    <table cellspacing="0" cellpadding="2" border="0" style="margin-top: 10px;">
        <tr>
            <td style="padding-right: 5px;">
                <select id="sel"></select>
            </td>
            <td><input type="button" value="Remove" onclick="remove();"></td>
        </tr>
    </table>
    </div>
    <script>var sel = document.getElementById("sel");
    var toolbar = new dhtmlXToolbarObject("toolbarObj");
    toolbar.setIconsPath("../common/imgs/");
    toolbar.loadXML("../common/dhxtoolbar_button.xml?etc=" + new Date().getTime(), updateList);
    function add() {
        var id = String(new Date().getTime());
        var pos = Number(document.getElementById("txt1").value);
        toolbar.addSeparator(id, pos);
        updateList();
    }
    function getId() {
        var id = sel.options[sel.selectedIndex].value;
        return id;
    }
    function remove() {
        if (sel.options.length == 0) {
            return;
        }
        toolbar.removeItem(getId());
        updateList();
    }
    function updateList() {
        sel.options.length = 0;
        toolbar.forEachItem(function(itemId) {
            if (toolbar.getType(itemId) == "separator") {
                sel.options.add(new Option(itemId, itemId));
            }
        });
    }</script>