In this tutorial, we will share a how to remove inline styles using JavaScript code. If you want to remove the all inline CSS code from your webpage, then keep close attention in this tutorial as I am going to share small code hacks which remove the inline CSS codes.
Use the following code in your file inside the HEAD tag.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
function remove_inline_styles(all) { var i = all.length; var j, is_hidden; //CSS attributes. var attr = [ 'align', 'background', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'color', 'face', 'height', 'hspace', 'marginheight', 'marginwidth', 'noshade', 'nowrap', 'valign', 'vspace', 'width', 'vlink', 'alink', 'text', 'link', 'frame', 'frameborder', 'clear', 'scrolling', 'style' ]; var attr_len = attr.length; while (i--) { is_hidden = (all[i].style.display === 'none'); j = attr_len; while (j--) { all[i].removeAttribute(attr[j]); } if (is_hidden) { all[i].style.display = 'none'; is_hidden = false; } } } |
You can call the above function in your code like below example:
1 2 |
var all = document.getElementsByTagName('*'); remove_inline_styles(all); |
Refference: https://gist.github.com/262366
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.