Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the CSS file

I am using spring MVC with jsp page for presentation, i have three tab suppose A,B and C in one jsp page. While clicking on A tab the css file such as aa.css have being loading in head tag with respective div is shown and the same way on click on B and C. The main problem is once the Three .CSS file is being loaded it overwrite each other. Also i want to remove css file from head which has being loaded on click of any of above tab using jquery as shown below.

  $("#A").click(function(){
     alert("Remove bb and cc.css file form head tag");
  });

any idea will help me lot.

Thanks.

like image 705
ASUR Avatar asked Oct 12 '12 11:10

ASUR


People also ask

Can I delete CSS files?

You can't delete CSS files through Javascript on the browser because that's a client-side scripting language.

How do I remove all CSS from a website?

Try this: $('link[rel="stylesheet"]'). remove(); This will remove all stylesheets (all the styles applies due to those stylesheets) from the page.

How do I delete unused CSS files?

If you want to remove unused CSS entirely, you can use a tool such as PurifyCSS to find out how much CSS file size can be reduced. Once you get the CSS code you should eliminate, you have to remove it manually from the page.

How do I remove all CSS from a class?

To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.


3 Answers

Give an id to the <link> tag.

<link rel="stylesheet" href="style1.css" id="style1" />
<link rel="stylesheet" href="style2.css" id="style2" />

And use this code:

$("#A").click(function(){
    $("#style1").attr("disabled", "disabled");
});

Note: While there is no disabled attribute in the HTML standard, there is a disabled attribute on the HTMLLinkElement DOM object.

The use of disabled as an HTML attribute is non-standard and only used by some Microsoft browsers. Do not use it. To achieve a similar effect, use one of the following techniques:

  • If the disabled attribute has been added directly to the element on the page, do not include the <link> element instead;
  • Set the disabled property of the DOM object via scripting.
like image 155
Praveen Kumar Purushothaman Avatar answered Nov 15 '22 19:11

Praveen Kumar Purushothaman


I had to disable css files without being able to specify an id, so to remove the following css file:

<link rel="stylesheet" type="text/css" href="http://localhost:8092/bootstrap/css/bootstrap.min.css" disabled="disabled">

I added this script

<script type="text/javascript">
  $(document).ready(function() {
    $('link[href*="bootstrap.min.css"]').attr("disabled", "true");
  }
</script>
like image 25
kuhr Avatar answered Nov 15 '22 20:11

kuhr


You can unload a css by disabling it as follows:

$("#A").click(function(){
    $("link[href*=bb.css]").attr("disabled", "disabled");
    $("link[href*=cc.css]").attr("disabled", "disabled");
    $("link[href*=aa.css]").removeAttr("disabled");
});
like image 31
Md Toufiqul Islam Avatar answered Nov 15 '22 20:11

Md Toufiqul Islam