I know how to remove attribute from a single element, there are already some posts about that:
$(\"div.preview\").removeAttr(\"style\");
Th
try: $("div.preview").children().removeAttr("style");
or: $("div.preview").find("*").removeAttr("style");
to get grandchildren too.
$("div.preview,div.preview *")).removeAttr("style")
You can use the wildcard selector *
to select everything underneath div.preview
.
jsFiddle
$('div.preview *').removeAttr('style');
RE: your related question, if we had a string instead of DOM elements. We could convert them into jQuery objects, remove the attribute as above and then convert them back (if desired).
jsFiddle
// jQuery extension to get an element's outer HTML
// http://stackoverflow.com/a/2419877/1156119
jQuery.fn.outerHTML = function(s) {
return s
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
};
var string = '<div class="preview"><p style="font-size:15px;">....</p><div>'
var elements = $(string);
elements.find('*').removeAttr('style');
var withoutStyles = elements.outerHTML();
alert(withoutStyles);
$("div.preview, div.preview *").removeAttr("style");
Try doing this
$("#frameDemo").contents().find("#div_id").parent('div').removeAttr('onclick');
$("#frameDemo").contents().find("#div_id").children('div').removeAttr('onclick');
Select the div, select it's children, then add the div back to the collection and remove class.
$('div.preview').find('[style]').addBack().removeAttr('style')
// replace addBack with andSelf for older jQuery
// if you don't want to remove it from the preview div, just leave addBack off.
however it's probably better to fix the editor rather than fix the results in the long run.