What does the innerHTML in JavaScript mean, and how do you use it?

Source: Internet
Author: User

innerHTML in JS is bidirectional: Gets the contents of an object or inserts content into an object;
such as: <div id= "AA" > This is Content </div>, we can pass document.getElementById (' AA '). InnerHTML to get the embedded content of an object with ID AA;
You can also insert content on an object, such as document.getElementById (' abc '). Innerhtml= ' This is the inserted content '; This allows you to insert content into an object with an ID of ABC



For the innerHTML property, almost all elements have a innerHTML property, which is a string that sets or gets the HTML that is inside the object's start and end tags. (Gets the contents of the beginning and end of the current HTML tag)

Grammar

Tablerowobject.innerhtml=html

Instance

The following example returns the inner HTML for the table row:



<script type= "Text/javascript" >

function getinnerhtml () {

Alert (document.getElementById ("TR1"). InnerHTML);

}

</script>


<body>

<table border= "1" >

<tr id= "TR1" ><td>Firstname</td><td>Lastname</td></tr>

<tr id= "TR2" ><td>Peter</td><td>Griffin</td></tr>

</table>

<input type= "button" onclick= "getinnerhtml ()" value= "Alert InnerHTML of Table row"/>

</body>

What does the innerHTML in JavaScript mean, and how do you use it?

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.