Skip to content

Instantly share code, notes, and snippets.

@jonathanstark
Created June 19, 2014 18:24
Show Gist options
  • Save jonathanstark/22ee69e86b0f9177fd2f to your computer and use it in GitHub Desktop.
Save jonathanstark/22ee69e86b0f9177fd2f to your computer and use it in GitHub Desktop.
Uncomment HTML
/* I didn't write this snippet but I can't remeber where I found it. PLMK if you know who the original author is :) */
(function($) {
$.fn.uncomment = function(recurse) {
$(this).contents().each(function() {
if (this.hasChildNodes()) {
$(this).uncomment(recurse);
} else if (this.nodeType == 8) {
// Need to "evaluate" the HTML content,
// otherwise simple text won't replace
var e = $('<span>' + this.nodeValue + '</span>');
$(this).replaceWith(e.contents());
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment