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.
Using jQueryWith the $. ajax() method, you can load the CSS from the server and enclose the content within the <style> tags, and finally append it at the end of the <head> element of the current document.
jQuery Manipulating CSSaddClass() - Adds one or more classes to the selected elements. removeClass() - Removes one or more classes from the selected elements. toggleClass() - Toggles between adding/removing classes from the selected elements. css() - Sets or returns the style attribute.
JavaScript can also be used to load a CSS file in the HTML document.
Save this question.
Append it to your head:
$("head").append("<link id='yournewcss' href='hi-res.css' type='text/css' rel='stylesheet' />");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With