Get HTML Content without comment lines using jquery -
look @ 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 know give output above only. question is, there anyway can output without commented lines?
you can create clone , remove comments nodes it(if don't want modify 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
Comments
Post a Comment