Last active
September 29, 2015 13:50
-
-
Save eagafonov/09896ecfdd326f0c5d75 to your computer and use it in GitHub Desktop.
jQuery plugin to dump HTML tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// playground http://jsfiddle.net/1ssfjxu1/1/ | |
$.fn.htmldump = function() { | |
function walk(element, callback) { | |
if (callback) { | |
callback.apply(element); | |
} | |
$(element).children('*:not(script)') | |
.each(function(i, child) {walk(child, callback)}); | |
}; | |
function wipe_text_nodes() { | |
$(this).contents().filter(function(){return this.nodeType != 1}).remove(); | |
} | |
var little_me = this.clone(); | |
little_me.find('script,.htmldumper').remove(); | |
little_me.find('svg').html(''); | |
walk(little_me, wipe_text_nodes); | |
return little_me.html(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment