March 28, 2010

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



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Remove All Stylesheets from a Page using jQuery"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions