attribute is the meaning of attributes, the article only partially compatible with IE and FF attribute related to the introduction.
Attributes: Gets an attribute as an object
GetAttribute: Gets the value of a property
SetAttribute: Creates a property and bundles a value to the property at the same time
CreateAttribute: Create only one property
RemoveAttribute: Delete a property
GetAttributeNode: Gets a node as an object
Setattributenode: Create a node
Removeattributenode: Delete a node
Attributes can get an attribute in an object and invoke it as an object, and note that to use "[]" here, ie can use "()" here, in view of compatibility issues, to use "[]". On the use of attributes properties, IE and FF have great differences, this is not much introduced.
How to use attributes: (IE and FF General)
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>< C4/><script>
var d = document.getElementById ("SSS"). attributes["value"];
document.write (d.name);
document.write (d.value);
Show Value AAA
</script>
Getattribute,setattribute,createattribute,removeattribute The concept of four brothers is relatively easy to understand, the use of the method is relatively simple, the only need to pay attention to these points:
1, CreateAttribute in use does not need object-based, Document.createattribute () can be.
2, Setattribute,createattribute in use when not to use the word name,type,value, ie and FF reaction is strange difficult to understand.
3, CreateAttribute in use if only the definition of the name, there is no d.nodevalue = "Hello"; the statement defines the value, the FF will be considered an empty string, ie is undefined, note that this can be.
How to use GetAttribute:
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>< C4/><script>
var d = document.getElementById ("SSS"). GetAttribute ("value");
document.write (d);
Show AAA
</script>
How to use setattribute: (You'll find a property called good hello)
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>< C3/><script>
var d = document.getElementById ("SSS"). setattribute ("Good", "Hello");
Alert (document.getElementById ("T"). InnerHTML)
</script>
How to use CreateAttribute: (one more empty attribute named good)
How to use RemoveAttribute: (One Less)
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>< C3/><script>
var d = document.getElementById ("SSS"). RemoveAttribute ("value");
Alert (document.getElementById ("T"). InnerHTML)
</script>
Getattributenode,setattributenode,removeattributenode three methods are characterized by the direct operation of a node (nodes), Removeattributenode at the beginning always use the wrong, But when you fully understand the meaning of node, you can apply it freely.
How to use GetAttributeNode:
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>
<script>
var d = document.getElementById ("SSS"). GetAttributeNode ("value");
document.write (d.name);
document.write (d.value);
Show Value AAA
</script>
How to use Setattributenode:
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body>< C3/><script>
var d = document.createattribute ("good");
document.getElementById ("SSS"). Setattributenode (d);
Alert (document.getElementById ("T"). InnerHTML);
</script>
How to use Removeattributenode:
<body>
<div id = "T" ><input type = "hidden" id = "SSS" value = "AAA" ></div>
</body> ;
<script>
var d = document.getElementById ("SSS"). GetAttributeNode ("value")
document.getElementById ("SSS"). Removeattributenode (d);
Alert (document.getElementById ("T"). InnerHTML);
</script>
More about the attributes of the problem, can be w3school in the query!
The above JS attribute operation details are small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.