javascript domElement .attr(attributeName,[attributeValue])
javascript domElement .attr( attributeName,[attributeValue] ) Target: Get/Set DOM element attribute. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll In case of DOM NodeList first Node Element is processed for get and set to all elements. Description : get/set attribute of DOM element. if attributeValue is passed then it set the attribute and return element itself, otherwise return attribute of element. If attributeValue is blank string then it remove attribute. Note: after setting the attribute of DOM elements it return the element/elementList. Syntax: DOMElement.attr( 'attributeName',[attributeValue] ) DOMNodeList.attr( 'attributeName',[attributeValue] ) HTMLCollection.attr( 'attributeName',[attributeValue] ) Usase: document.getElementById('txtName').attr("maxlength",10) it sets the maxlength of textbox with 10 character and return textbox element document.getElementById('txtNam...