spacer
Yehuda Shiran January 28, 2001
The Attribute Node
Tips: January 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Later browsers (Netscape 6+, Mozilla, IE6+, Opera 7+) support the attribute object. One way to create an attribute node is via the document.createAttribute() command:

attObj = document.createAttribute("foo");

The attribute node is very unique. It is not anyone's child, and it does not belong to the document object. It is a depository for an attribute value. You change the attribute value via:

attObj.value = newValue;

You can query the attribute name and its value with attObj.name and attObj.value, respectively. We put the following lines in the header of this tip:

if (document.createAttribute) {
   attObj = document.createAttribute("A JavaScript Reference");
   attObj.value = "Doc JavaScript";
}

Click the following buttons to detect the attribute name and value in any of the browsers mentioned above. Click them in other browsers and you will receive an error message or nothing at all will happen:

Here is how we defined these buttons:

<FORM>
<INPUT TYPE="button" 
       onClick="alert(attObj.name)" 
       VALUE="Print Attribute Name">
</FORM>
<FORM>
<INPUT TYPE="button" 
       onClick="alert(attObj.value)" 
       VALUE="Print Attribute Value">
</FORM>


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business