Sobin Augustine
Sobin Augustine

Reputation: 3765

How to disable all inline styling with JavaScript?

Need to disable all inline styling of every DOM elements from a html document.

Saw some solution to override inline styles but i need to clear all inline styling. Also may be done with the code formatting but not interested with that also,

Is there a way to do this with JavaScript.

Upvotes: 3

Views: 186

Answers (6)

Jai
Jai

Reputation: 74738

With javascript:

document.getElementsByTagName("*").removeAttribute("style");

With jQuery (my personal choice):

$('*').removeAttr('style');

Upvotes: 1

rahulbehl
rahulbehl

Reputation: 2709

Yes, try

$('*').removeAttr( "style" );

as it will remove style attribute from each element of the page.

Upvotes: 0

C M
C M

Reputation: 703

for single element or group of element

use

$('elementselector').removeAttr('style');

for removing from entire page

use

$(*').removeAttr('style')

hope this helps...

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

you could also do:

document.getElementsByTagName("*").removeAttribute("style")

Upvotes: 1

Rich
Rich

Reputation: 5731

Try this code:

$('*').removeAttr( "style" );

Upvotes: 1

Try

$('*').removeAttr('style');

removeAttr

Upvotes: 4

Related Questions