In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how javascript modifies the attributes of element nodes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Modification method: 1, use the setAttribute () method to modify the value of the node attribute, syntax "node .setAttribute (attribute name)"; 2, use the removeAttribute () method to delete the specified attribute, syntax "node .removeAttribute (attribute name)".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Javascript modifies the attributes of an element node
The setAttribute () method sets the property value
Use the setAttribute () method of an element to set the attribute value of an element. The usage is as follows:
SetAttribute (name, value)
The parameters name and value represent the attribute name and the attribute value, respectively. Property names and values must be passed as strings. If the specified attribute exists in the element, its value is refreshed; if not, the setAttribute () method creates the attribute and assigns a value to the element.
Red box and blue box var red = document.getElementById ("red"); / / get the reference var blue= document.getElementById of the red box ("blue"); / / get the reference red.setAttribute of the blue box ("title", "this is the red box"); / / set the title property and value blue.setAttribute ("title", "this is the blue box") for the red box object; / / set the title property and value for the blue box object
The removeAttribute () method deletes an attribute
Use the element's removeAttribute () method to delete a specified attribute. The usage is as follows:
RemoveAttribute (name)
The parameter name represents the attribute name of the element.
Example:
_ window.onload = function () {/ / event handler function var table = document.getElementByTagName ("table") [0] when the binding page is loaded; / / get the reference to the outer box of the table var del = document.getElementById ("del"); var reset = document.getElementById ("reset"); del.onclick = function () {table.removeAttribute ("border") } reset.onclick = function () {table.setAttribute ("border", "2");} data table deletion and recovery
In the above example, two buttons are designed and bound to different event handlers. Click the "delete" button to call the removeAttribute () method of the table to clear the border of the table, and click the "restore" button to call the setAttribute () method of the table to reset the thickness of the cousin.
Thank you for reading! This is the end of this article on "how javascript modifies the attributes of element nodes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.