It is a script in javascript that add a <div></div> and add an id, a class, html.. I want to add name attribut too and my code doesn’t works, but I wonder why..
There https://developer.mozilla.org/fr/DOM/element I have seen that element.name = 'newname'; can edit it..
function newgroup() {
var e = document.getElementsByName('group');
var nb = e.length + 1
div = document.createElement("div");
div.id = 'group'+nb;
div.className = 'panel_drop';
div.name = '1';
div.innerHTML = '<h5>Group '+nb+'</h5>';
div.innerHTML += '<div class=\'drop_zone\'></div>';
document.getElementById('groups').appendChild(div);
}
The
nameattribute of an HTML element is not mapped to thenameproperty of the corresponding DOM element for all elements, but only for certain types of elements, and DIV elements are not one of them.You can check for which types of HTML elements the
nameattribute is specified here: http://www.whatwg.org/specs/web-apps/current-work/multipage//section-index.html#attributes-1Since the HTML standard doesn’t specify a
nameattribute for DIV elements, my recommendation is to not use such an attribute/property on DIV elements. If you need to attach additional information to your DIV elements, considerdata-*attributes.