JS's InnerHTML

Source: Internet
Author: User

Definition and usage

The InnerHTML property is used to set or return the HTML content between the specified labels .

Grammar
object.innerhtml = "HTML"; // Set var html = object.innerhtml; // Get
Example 1

Gets the InnerHTML (HTML content) of the paragraph P

<HTML><Head><Scripttype= "Text/javascript">functiongetinnerhtml () {alert (document.getElementById ("Test"). InnerHTML);}</Script></Head><Body><PID= "Test"><FontColor= "#000">Hi Bean Shell www.hi-docs.com</Font></P><inputtype= "button"onclick= "getinnerhtml ()"value= "Tap" /></Body></HTML>
Example 2

Set InnerHTML (HTML content) for paragraph p

<HTML><Head><Scripttype= "Text/javascript">functionsetinnerhtml () {document.getElementById ("Test"). InnerHTML= "<strong> Set HTML content for tags </strong>";}</Script></Head><Body><PID= "Test"><FontColor= "#000">Hi Bean Shell www.hi-docs.com</Font></P><inputtype= "button"onclick= "setinnerhtml ()"value= "Tap" /></Body></HTML>

Example 3: Document.body.innerHTML

<HtmL><Head><Metacontent= "Text/html;charset=utf-8"http-equiv= "Content-type">    <Scripttype= "Text/javascript">window.onload= function(){         varArrli={my friend: ['Wow, haha .','Robust','Farmer Spring'], classmate: ['Coffee','Juice','Wine']}; varN= -1         for(varIinchArrli) {N++; Document.body.innerHTML+= '<ul>'+I+'</ul>'; varul=document.getElementsByTagName ('ul');  for (varJ= 0; J<Arrli[i].length; J++) {ul[n].innerhtml+= '<li>'+Arrli[i][j]+'</li>';        }; }    }    </Script></Head><Body></Body></HtmL>

JS's InnerHTML

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.