views:

424

answers:

3

Hi there,

does anyone know if its possible to remove a css link at run time... Basically i have partial HTM files in a directory so hence if i add a css link (so i can use my design time editor) then this link isn't valid at runtime and i don't need it as my CSS is in another file.

I just want to be able to strip it out when i load it in.. Anyone know of something that can do this..??

Same goes for the paths on images etc.. while in design time i need them like ....\content\images etc so i can design with ease ...

but at runtime i need them to be content\images etc

Anyone know of a good addon for jquery, framework or similar??

Thanks

+2  A: 

You can access a link tag by an id. So try this (using jQuery):

$('#testLink').attr('href','')

That should remove any styling associated with that stylesheet. I just tried it with FF3, and it worked.

geowa4
You don't need to add an ID, you could also just select by URL: $('link[href^=test.css]').remove();Though I agree with the other answers, this should be fixed on deployment, not at runtime.
robertc
+2  A: 

If I understand correctly: you want your project to use an 'offline' stylesheet and when you upload the project you want to use the original stylesheets?

Firstly: Make sure the file structure is the same offline as it will be online, then you won't have URL problems. At least you'll be able to sort out the problems on your localhost before you make your project live.

Secondly: Why complicate things with javascript? Just comment out your 'design-time' stylesheet(s) before you upload your project.

<link href="/styles/live.css" rel="stylesheet" />
<!-- <link href="/styles/design.css" rel="stylesheet" /> -->

If this is not what you were looking for, please clarify your question.

Phaze Phusion
+1  A: 

If I understand correctly you wan't to rewrite urls for images and stylesheets at the client side.

Please don't.

Make sure you properly set up your design enviroment so that it is as closely to your production enviroment. Consider what would happen if you use javascript to rewrite image paths and someone who doesn't have javascript visits your site. They would not be able to see any of the images. All the images would display as image not found.

Pim Jager