11

i have a website that uses screen.css as main CSS file. I added this for monitors with a 1024+ resolution.

$(document).ready(function(){
if(screen.width > 1024) {
    $('link').attr('href','hi-res.css');
}
});

The problem is that hi-res.css is replacing screen.css... i don't want to replace it, i just want to load an additional css in that case. Any ideas? Thanks.

Andres SK
  • 10,779
  • 25
  • 90
  • 152

4 Answers4

27

Append it to your head:

$("head").append("<link id='yournewcss' href='hi-res.css' type='text/css' rel='stylesheet' />");
Gert Grenander
  • 16,866
  • 6
  • 40
  • 43
2

You want to .append :o)

$(document).ready(function(){
    if(screen.width > 1024) {
       $('head').append('<link href='hi-res.css' type='text/css' rel='stylesheet' />')
    }
 });
HurnsMobile
  • 4,341
  • 3
  • 27
  • 39
1

Try this.. instead of replacing append one.

$('head').append($('<link>').attr('href','hi-res.css')); 
Teja Kantamneni
  • 17,402
  • 12
  • 56
  • 86
0

You might want to check out the following link:

How to load up CSS files using Javascript?

Community
  • 1
  • 1
James O'Sullivan
  • 498
  • 1
  • 4
  • 12