Look at the following code.
HTML:
<div>
<p>sdfsdfsfsf</p>
<!--<p>testing</p>-->
</div>
JQUERY
$(document).ready(function(){
alert($("div").html());
});
OUTPUT
<p>sdfsdfsfsf</p>
<!--<p>testing</p>-->
As I know it will give the output like above only. My Question is, Is there anyway we can get the output without the commented lines?
You can create a clone and then remove all the comments nodes from it(if you don't want to modify the original dom)
$(document).ready(function () {
var $clone = $("div").clone();
$clone.contents().contents().addBack().filter(function () {
return this.nodeType == Node.COMMENT_NODE;
}).remove();
console.log($clone.html());
});
Demo: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With