Issue
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?
Solution
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
Answered By - Arun P Johny
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.