Remove All Stylesheets from a Page using jQuery

Here’s a very simple piece of code that removes all stylesheet links from a Page using jQuery

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Remove All Stylesheets From a Page</title>
<
link href="CSS/RoundCorners.css" rel="stylesheet" type="text/css" />
<
link href="CSS/FloatDes.css" rel="stylesheet" type="text/css" />
<
script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</
script>
<
script type="text/javascript">
$(function() {
$("#removeAll").click(function() {
$('link[rel=stylesheet]').remove();
});
});
</script>
</
head>
<
body>
<
div class="sub-level"></div>
<
br />
<
input id="removeAll" type="button" value="Remove All Stylesheets" />
</
body>
</
html>

Originally the page with the stylesheets applied looked similar to the following:

remove stylesheets jquery

and after the Button is clicked and the stylesheets removed, the page looks like this

remove stylesheets jquery






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

2 comments:

Anonymous said...

worst post ever.

Anonymous said...

Wouldn't go that far; but it is over-simplistic. What about stylesheets inserted via @import within an inline style?