JQuery, Get HTML Comments Node

by Prashanth bhat

HTML

<button>Load the Content!</button>
<br> <!--
    <img src="http://lorempixel.com/200/100/animals/1" width="200" height="100"><br>-->
<div id="fake-elem-container">
    <!--
    <img src="http://lorempixel.com/200/100/animals/1" width="200" height="100">
    <img src="http://lorempixel.com/200/100/animals/2" width="200" height="100">
    -->
</div>
<div id="container"><!--
    <img src="http://lorempixel.com/200/100/animals/1" width="200" height="100">
    <img src="http://lorempixel.com/200/100/animals/2" width="200" height="100">
    --></div>

CSS

body {padding:30px;text-align:center}

JavaScript

// Dapat digunakan untuk menunda pemuatan elemen tanpa AJAX

function loadImage() {
    $(document).contents().filter(function() {
        return this.nodeType == 8;
    }).each(function(i, e) {
        $(document).html(e.nodeValue);
        console.log(e.nodeValue);
    });
}

$('button').on("click", loadImage);