Wednesday, 15 May 2013

javascript - Get HTML Code of Element (innerHTML + element tags) -


How to obtain the HTML code of the element in JavaScript with the existing element tag?

For example

Lt; / Body & gt; & Lt; Body & gt; & Lt; Div & gt; & Lt; Div class = "big" & gt; & Lt; P & gt; Some time ago & lt; / P & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Body & gt; Var x = document.getElementsByClassName ('bigger') [0]

And now I want to get the HTML code of X:

  '& lt; Div class = "large" & gt; & Lt; P & gt; Sometext & lt; / P & gt; & Lt; / Div & gt; ' 

Not only:

 ' & lt; P & gt; Some time ago & lt; / P & gt; Like internal HTML  

Is this an easy way to do it?

  var div = document.createElement ("div"); Div.id = '_fooo'; Var parent = x.parentNode; Parent.insertBefore (div, x); Div.appendChild (x); Document.getElementById ('_fooo'). Internal HTML  

First of all, your HTML block is an error & lt; Input & gt; is an empty element, and can not have hair element in it, then

   

Not a valid HTML.

However, the answer to your question is 'external HTML' attribute.

& lt; Div & gt;

  and 
type = "submit" class = "big" with input & gt; By changing tags, & gt; & Lt; P & gt; Sometext & lt; / P & gt; & Lt; / Div & gt; Var x = document.getElementsByClassName ('big') [0]; Var Output = X.uter HTML / Return '& lt; Div type = "submit" square = "big" & gt; & Lt; P & gt; Some time ago & lt; / P & gt; & Lt; / Div>

No comments:

Post a Comment