Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplest way to remove all the styles in a page

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?

like image 426
tic Avatar asked Feb 12 '12 21:02

tic


People also ask

How do you unset all styles in CSS?

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.

How do I remove all styles from an element?

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.

How do I delete style sheets?

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.


1 Answers

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));
like image 188
Rajkeshwar Prasad Avatar answered Oct 06 '22 15:10

Rajkeshwar Prasad