The following two methods may be used to create a new property node provided to the node specific elements.
var node = document.getElementById('div1'); var a = document.createAttribute('my_attrib'); a.value = 'newVal'; node.setAttributeNode(a); // 或者 node.setAttribute('my_attrib', 'newVal');
Note: The attribute names and values here can be customized.