One, gets the value of the property of a specific element node _getattribute ()
1, the GetAttribute () method gets the value of an attribute in the element. It is somewhat different from the method used to get property values directly from the.
<script type= "Text/javascript" >window.onload=function(){ varbox = document.getElementById (' box '); alert (BOX.BBB); //Gets the custom attribute value of the element, non IE does not support custom properties No, the result is undefinedAlert (Box.getattribute (' BBB '));//get custom property values for an element this method can be compatible with custom propertiesAlert (Box.getattribute (' class '));//The getattribute method gets the value of the class attribute in the tag when using classname in ie6,7, and other uses of class need to be compatible //get the value of the class property across browsers if(Box.getattribute (' className ') = =NULL) {alert (Box.getattribute (' Class ')); }Else{Box.getattribute (' ClassName '); } };</script>Second, set the value of the attribute of the specific element node _setattribute ()
1, the SetAttribute () method sets an attribute and value in the element. It needs to accept two parameters: property name and value. If the property itself already exists, it will be overwritten.
<script type= "Text/javascript" > function () { var box = document.getElementById (' box '); Box.setattribute (' title ', ' I am the title '); alert (box.title); }; </script>
2, the use of this method to set the class and style property is not valid in ie6,7 (so not recommended)
<script type= "Text/javascript" > function() { var box = document.getElementById (' box '); Box.setattribute (' style ', ' color:green '); // ie6,7 Invalid Box.setattribute (' class ', ' pox '); // ie6,7 Invalid }; </script>
Three, removeattribute () can remove attributes from an HTML element. IE6 not supported
<script type= "Text/javascript" > function () { var box = document.getElementById (' box '); Box.removeattribute (' title '); alert (box.title); }; </script>
JavaScript dom_ Get/Set/remove properties of a specific element node _getattribute ()/setattribute ()/removeattribute ()