I'm trying to add a css file depending on the browser width and not sure how to go about it.
In this case, if the browser window is bigger than 1200 width it will add the css file. I know how to do this so it works with refresh but i want it so if the browser is being resized while active on the page the css file's will change.
Here's what I have at the moment, i'm probably going in the wrong direction im not too sure:
<link rel="stylesheet" type="text/css" id="smallS" href="<?php bloginfo('template_directory'); ?>/css/default-960.css" />
<script>
$(function(){
$(window).resize(function(){
var w = $(window).width();
if (w > '1200') {
document.write('<link rel="stylesheet" type="text/css" id="largeS" href="<?php bloginfo('template_directory'); ?>/css/default.css" />');
}
else {
if($('#largeS').length > 0) {
$('#largeS').remove();
}
}
});
});
</script>
This is what I had before, but its not what I'm looking to do:
if ((screen.width>=1024))
{
document.write('<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/default.css" />');
}
Any thoughts?
if (w > '1200'), try taking out the single quotes of the1200