JSFiddle - React, Tailwind, and code Playground
by dhchow
HTML
<div class="megaphone_content" style="width:100%; height:100%;" contenteditable="true"><span class="Apple-style-span" style="line-height: normal; font-size: 10px; "><ul id="filter-results" class="results" style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; "><li id="update_305475" class="r cotweet inbound has_recipient imported twitterer reply" style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 1px; margin-right: 5px; margin-bottom: 1px; margin-left: 5px; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px; position: relative; z-index: 7; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; border-bottom-right-radius: 5px 5px; border-bottom-left-radius: 5px 5px; "><div class="rc in" style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><div class="c" style="list-style-type: none; list-style-position: initial; list-style-image: initial; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 40px; padding-top: 5px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; background-image: url(http://ent-new-working.cotweet.com/images/_app/results/bg_reply.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(241, 250, 255); border-right-color: rgb(221, 224, 226); border-left-color: rgb(221, 224, 226); border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(241, 243,...
JavaScript
if (!Array.indexOf) {
Array.prototype.indexOf = function (obj, start) {
for (var i = (start || 0); i < this.length; i++) {
if (this[i] == obj) {
return i;
}
}
};
}
var element = $(".megaphone_content");
$(':empty', element).filter(function(){
return ["br", "p", "div"].indexOf(this.tagName.toLowerCase()) != -1}).remove();
var nodes = $("*", element); //element.children();
var sanitizedNodes = nodes.map(function() {
var node = $(this);
node.removeAttr("class");
node.removeAttr("style");
console.dir("node", node);
return this;
})
console.log(sanitizedNodes);
element.empty();
element.append(sanitizedNodes);