0

I want to reset remove or make initial all the css properties defined in an external css file. I want the solution should also work when I edited/added/removed properties in css file.

So solutions in here don't work.

For example $('div').css('width','');, is not a solution cause it clears the width property in a HARDCODED way.
Also solutions like $('div').attr('style',''); does not work cause I do not use inline styling, also again $('div').removeClass(''); is not a valid solution. Any answer would be appreciated, thanx.

You can playaround the code here: http://codepen.io/ertugrulmurat/pen/JEhfe

And; How to dynamically remove a stylesheet from the current page is not a solution, another side effect of this is that it removes all styles for all elements, this is not the case wanted

Community
  • 1
  • 1
Ertugrul
  • 35
  • 7
  • Remove the stylesheets from the dom? – Etheryte Aug 09 '14 at 09:46
  • 1
    Why not tell us why you need to do this, as it's a very strange requirement, and there's probably a better solution ? – adeneo Aug 09 '14 at 09:47
  • See this post, http://stackoverflow.com/questions/5033650/how-to-dynamically-remove-a-stylesheet-from-the-current-page, on how to remove stylesheets using jQuery. – joeltine Aug 09 '14 at 09:51
  • Why don't you define a default Style in one class and just remove this certain class, when you don't want an element to be styled anymore? – Nico O Aug 09 '14 at 09:58
  • @adeneo i copy style from one div to other and from that to the other, when i do this copied properties shows 'cascaded' property, meaning both keeps the old and new properties, while i only want to keep the new ones' properties. – Ertugrul Aug 09 '14 at 10:11
  • @Nico O, yes this is a solution but i want a solution where an external css file is used – Ertugrul Aug 09 '14 at 10:43
  • @Nit look at the edit why this is not solution – Ertugrul Aug 09 '14 at 11:39

1 Answers1

0

Just use this $('link[rel=stylesheet][href~="external_css_link.css"]').remove(); and remove the link of the css file which you don't want in similar manner you can again add the file

UPDATE I tested the same in local file system where css is other file and run the same code and found that the style is removed completely and it behave in complete different manner as it working in the online javascript editor jsfiddle or any other because they internally include the css in the page they don't include the an external link thats why

$('link[rel=stylesheet]').remove();

not work here in your sample in other way it remove the style completely

  • please test the same in local system exactly as you trying to do then then tell what really happens if it is same or different?? – Arjun Verma Aug 09 '14 at 12:42