GetAttribute () How to use small notes

Source: Internet
Author: User

Today in a lesson online review js, suddenly stuck in a small example. Repeated several times is an error. Finally, we found the source of the error.

Here is a record, beware of later forget again.

Error code:

<Body>   <PID= "Intro">Course List</P>      <ul>          <Lititle= "1th li">Html</Li>          <Li>Css</Li>          <Lititle= "3rd li">Javascript</Li>          <Lititle= "4th li">Jquery</Li>          <Li>Html5</Li>      </ul>  <P>The following is a non-empty Li tag that gets the title value:</P><Scripttype= "Text/javascript">    varCon=document.getElementsByTagName ("Li");  for (varI=0; I<Con.length;i++){      vartext=Con.getattribute ("title"); if(Text!=NULL) {document.write (text+"<br>"); }    }  </Script> </Body>

Correct code:

<Body>   <PID= "Intro">Course List</P>      <ul>          <Lititle= "1th li">Html</Li>          <Li>Css</Li>          <Lititle= "3rd li">Javascript</Li>          <Lititle= "4th li">Jquery</Li>          <Li>Html5</Li>      </ul>  <P>The following is a non-empty Li tag that gets the title value:</P><Scripttype= "Text/javascript">    varCon=document.getElementsByTagName ("Li");  for (varI=0; I<Con.length;i++){      vartext=Con[i].getattribute ("title"); if(Text!=NULL) {document.write (text+"<br>"); }    }  </Script> 

Note When you use the GetAttribute () method, the obtained label element must be labeled subscript. GetAttribute () considers an element as an array. If you do not write the subscript getattribute () error.

GetAttribute () How to use small notes

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.