최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

■ 프론트엔드 ■/HTML

innerHTML

serpiko 2013. 10. 13. 21:41

The innerHTML Property

The easiest way to get the content of an element is by using the innerHTML property.

The innerHTML property is useful for getting or replacing the content of HTML elements.

Example

The following code gets the innerHTML from the <p> element with id="intro":

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<html>
 <body>

 <p id="intro">Hello World!</p>

 <script>
 var txt=document.getElementById("intro").innerHTML;
 document.write(txt);
 </script>

 </body>
 </html>

 

result)

 

 

 

The nodeName Property

The nodeName property specifies the name of a node.

  • nodeName is read-only
  • nodeName of an element node is the same as the tag name
  • nodeName of an attribute node is the attribute name
  • nodeName of a text node is always #text
  • nodeName of the document node is always #document

Note: nodeName always contains the uppercase tag name of an HTML element.


The nodeValue Property

The nodeValue property specifies the value of a node.

  • nodeValue for element nodes is undefined
  • nodeValue for text nodes is the text itself
  • nodeValue for attribute nodes is the attribute value

Get the Value of an Element

The following example retrieves the text node value of the <p id="intro"> tag:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<html>
 <body>

 <p id="intro">Hello World!</p>

 <script type="text/javascript">
 x=document.getElementById("intro");
 document.write(x.firstChild.nodeValue);
 </script>

 </body>
 </html>

 

result)

 

* editing : me (dothjin)

* source : http://www.w3schools.com/

'■ 프론트엔드 ■ > HTML' 카테고리의 다른 글

document.getElementById() - ID 접근  (0) 2013.10.13
DOM example  (0) 2013.10.13
document.getElementsByName() - name접근  (0) 2013.10.13
getElementById() - Method  (0) 2013.10.13
DOM - Methods and Properties  (0) 2013.10.13
댓글