Clear All Page Style For A Specific Div And It's Child Elements
I have some html being embeded on websites but is gets messed by the page it's embeded in's css. How can I make it so that doesnt happen... My content has a specific ID and it's cs
Solution 1:
Provided I understood your question correctly, you could recursively iterate through the child elements of your div
with JavaScript and reset the class
and style
attributes. See this fiddle or the following code snippet:
<html><head><styletype="text/css">.aClass {
font-size: 0.75em;
}
.anotherClass {
font-weight: bold;
color: Fuchsia;
}
</style><scripttype="text/javascript"src="jquery.js"></script><scripttype="text/javascript">functionremoveStuff(elem) {
elem.children().each(function() {
if ($(this).children().length > 0) {
$(this).removeClass();
$(this).removeAttr('style');
removeStuff($(this));
} else {
$(this).removeClass();
$(this).removeAttr('style');
}
});
}
</script></head><body><divid="myDiv"><spanclass="aClass">This span is classy.</span><divstyle="font-size: 2em;">
This div has style.
<spanclass="anotherClass">Lorem Ipsum.</span></div></div><ahref="javascript:removeStuff($('#myDiv'));">Remove classes & styles</a></body></html>
Post a Comment for "Clear All Page Style For A Specific Div And It's Child Elements"