The difference between 17.innerHTML and innertext

Source: Internet
Author: User

1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"2 "Http://www.w3.org/TR/html4/loose.dtd">3 <HTML>4 <Head>5 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312">6 <title>The difference between innerHTML and innertext</title>7     <Scripttype= "Text/javascript">8     9         functiontestinnerhtml () {Ten          One             varDiv1=document.getElementById ("Div1"); A          -             //innerHTML is to execute the following string as HTML code - div1.innerhtml="<font color= ' Red ' >hello1</font>"; the              -         } -          -         functionTestinnertext () { +          -             varDiv2=document.getElementById ("Div2"); +              A             //innertext is to treat the following string as a string, even if it is followed by an HTML statement that is executed as a string at             //div2.innertext= "<font color= ' Red ' >helllo2</font>" -              -             //textcontent and innertext function similar, but innertext Firefox browser does not support, Textcontent,ie browser does not support; Textcontent and innertext Google browser support - div2.textcontent="<font color= ' Red ' >hello2</font>"; -          -         } in      -     </Script> to </Head> +  - <Body> the  *     <inputtype= "button"value= "InnerHTML"onclick= "testinnerhtml ()"/> $     <DivID= "Div1"></Div>Panax Notoginseng     <inputtype= "button"value= "InnerText"onclick= "Testinnertext ()"/> -     <DivID= "Div2"></Div> the </Body> + </HTML>

The difference between 17.innerHTML and innertext

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.