How to remove stylesheet dynamically and append new stylesheet dynamically

If you want to remove loaded style that means at the time page loading we added stylesheet.

But after loading that when click on some thing if you want to remove the loaded styles and you want to add new styles to that page.

So by using jquery  it is simple to remove the loaded stylesheet and add new styles to it.

Just by simply injecting this lines into your code :

This line is to remove loaded style sheet:
$('link[rel=stylesheet]').remove();
 This line is to add new styles to the page
$('head').append('link rel="stylesheet" href="style2.css" type="text/css" /');
 OR

If you want to pass variable to href instead of direct name of the file it is also simple

$('head').append('link rel="stylesheet" href=+variblaename+".css" type="text/css" /');

Post a Comment

Analytics