I need to remove all the style definitions in a page using javascript, to obtain the same result as doing View > Page Style > No Style
in Firefox. Which is the simplest way?
There is a property called all that is being proposed for resetting all CSS properties for a given element to certain CSS-wide values - the value you want to use would be unset , which resets a property to either its inherited value if it inherits by default, or otherwise, its initial value.
Use the removeAttribute() method to remove all styles from an element, e.g. box. removeAttribute('style') . The removeAttribute method will remove the style attribute from the element.
Click the name of the template where you want to attach your stylesheet to select it in the inspector. Under the Head and Body Options in the inspector, you can click the X next to the linked stylesheets you'd like to remove. This will remove the stylesheet from all pages using this template.
Here is the ES6 goodness you can do with just one line.
1) To remove all inline styles (eg: style="widh:100px"
)
document.querySelectorAll('[style]')
.forEach(el => el.removeAttribute('style'));
2) To remove link external stylesheet (eg: <link rel="stylesheet"
)
document.querySelectorAll('link[rel="stylesheet"]')
.forEach(el => el.parentNode.removeChild(el));
3) To remove all inline style tags (eg: <style></style>
)
document.querySelectorAll('style')
.forEach(el => el.parentNode.removeChild(el));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With