Javascript compatibility -- getattribute (), setattribute () (get set attribute)

Source: Internet
Author: User

For front-end users, they always need to deal with compatibility, CSS compatibility, and JS compatibility. Here I summarize the compatibility of getattribute () and setattribute () in different browsers and how to solve these problems:

 1       <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >    2       <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  >    3       <  Head >    4       <  Title  > Kingwell </  Title  >    5       <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"   />   6       <  Body  >    7         8       <  Div  ID  = "Idheader"  Class  = "Class-header"  Title  = "Kingwell"  Status  = "1"  > </ Div  >    9       <  Label  ID  = "Forusername"  For  = "Username"  Title  = "Kingwell"  Status  = "1"  > </  Label  >    10        11       </  Body  >    12       </  Html  >   

 

 1       VaR El = Document. getelementbyid ("idheader" );  2 Alert (El. getattribute ("ID" ));  3   Alert (El. ID ); 4 IE firfox-> Idheader  5         6 Alert (El. getattribute ("class" ));  7       //  IE6, IE7-> null IE8, ie9, Firefox-> class-Header  8         9   Alert (El. Class );  10       //  IE6, IE7, IE8-> error ie9, Firefox-> undefined 11 Alert (El. getattribute ("classname" ));  12       //  IE6, IE7-> class-header; IE8, ie9, Firefox-> undefined  13         14   Alert (El. classname );  15       //  All-> class-Header  16         17         18       VaR Elfor = Document. getelementbyid ("forusername" );  19 Alert (elfor. getattribute ("" ));  20       //  IE6, IE7-> undefined IE8, 9, Firefox-> forusename  21         22 Alert (elfor. For  )  23       //  IE6 or IE7 reports an error. The other values are undefined.  24  Alert (elfor. Title)  25       //  Output all kingwell  26   Alert (elfor. status );  27       //  IE6-8-> 1 ie9, Firefox-> undefined  28         29 Alert (elfor. getattribute ("status" ))  30       //  Output all 1 

/* Summary:
1: We recommend that you use node. xxxx for general attributes.
2: We recommend that you use node. getattribute ("XXXX") for custom attributes ").
3: We recommend that you use node. getattribute ("XXX"), such as for in label, when the target is a keyword in Js.
4: Use classname instead of reserved words, such as class.
*/

 

Getattribute () and setattribute () are analyzed here.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.