Search code examples
javascriptjqueryhtmlinnerhtml

Html Code inside an <pre> tag, innerHTML doesnt return all the code


I want all the code inside an pre-tag but innerHTML or jquery : html() doesnt return all the code. Some things where cut off. Like doctype und head body tags etc.

<pre id="pre">
    <!DOCTYPE html>
    <html >
        <head></head>
        <body>    
            <div>asdfds</div>
        </body>    
    </html>
</pre>

When i alert the innerHTML of the #pre object it only alerts the div

http://jsfiddle.net/6o8xjtaq/1/

Is there any other possibility to solve this?


Solution

  • If you really want to do it, use a script

    <script id="pre" type="text/template">
    <!DOCTYPE html>
    <html >
        <head></head>
        <body>    
            <div>asdfds</div>
        </body>    
    </html>
    </script>
    
    $('#pre').text();