Modification method: 1. Use the setAttribute() method to modify the value of the node attribute, the syntax "node.setAttribute(attribute name, value)"; 2. Use the removeAttribute() method to delete the specified attribute, the syntax "node .removeAttribute(attribute name)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript modifies the attributes of the element node
setAttribute() method to set the attribute value
Use The element's setAttribute() method can set the element's attribute value. The usage is as follows:
setAttribute(name, value)
The parameters name and value represent the attribute name and attribute value respectively. Property names and property values must be passed as strings. If the specified attribute exists in the element, its value will be refreshed; if it does not exist, the setAttribute() method will create the attribute for the element and assign a value.
红盒子蓝盒子
removeAttribute() method removes attributes
Use the element's removeAttribute() method to remove the specified attribute. The usage is as follows:
removeAttribute(name)
Parameter name represents the attribute name of the element.
Example:
数据表格 |
In the above example, two buttons are designed and bound to different event handling functions. Click the "Delete" button to call the table's removeAttribute() method to clear the table border, and click the "Restore" button to call the table's setAttribute() method to reset the thickness.
[Related recommendations:javascript learning tutorial]
The above is the detailed content of How to modify the attributes of element nodes in javascript. For more information, please follow other related articles on the PHP Chinese website!