Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Remove inline style="..."
- // Preserve hidden content.
- //
- // Call the function like this:
- // var all = document.getElementsByTagName('*');
- // remove_style(all);
- //
- // Note: Selecting all elements in the page via a
- // wildcard query could be slow, depending on how
- // many elements are in the page. You could use a
- // smaller set of elements to be more performant.
- //
- // var set = document.getElementById('foo').getElementsByTagName('bar');
- // remove_style(set);
- //
- function remove_style(all) {
- var i = all.length;
- var j, is_hidden;
- // Presentational 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--) {
- all[i].style.display === 'none' ? is_hidden = true : is_hidden = false;
- j = attr_len;
- while (j--) {
- all[i].removeAttribute(attr[j]);
- }
- // Re-hide display:none elements,
- // so they can be toggled via JS.
- if (is_hidden) {
- all[i].style.display = 'none';
- is_hidden = false;
- }
- }
- }
Add Comment
Please, Sign In to add comment