Give help. Get help.

  • # January 22, 2013 at 3:06 am

    Hi guys,

    i want to ask, is it possible to load css using javascript ???

    because i have 2 css files, 1 for the desktop and the other one for the mobile browser/touch device

    # January 22, 2013 at 3:23 am

    It is indeed possible.

    var s = document.createElement(‘link’);
    s.setAttribute(‘href’, ‘style.css’);

    But sometimes using JavaScript isn’t the best idea. Have you thought about using media queries instead?

    # January 22, 2013 at 3:30 am

    Seconded. Use media queries instead of JavaScript.

    # January 22, 2013 at 3:40 am

    Here’s an introduction to media queries that Chris wrote:

    # January 22, 2013 at 4:01 am

    @rosspenman and @hugogiraudel, thanks a lot guys.

    # January 22, 2013 at 6:54 am

    The issue here is that there are two CSS files targeted specifically for different environments, desktop & mobile.

    Media queries could reduce this to a single CSS file but if the separate files are required then there is no reason that the ‘media query’ couldn’t be in the head of the page to load the css file appropriate to the screen/device width.

    Something like:

    # January 22, 2013 at 9:40 am

    media = all will media types of which there are many.

    If you want to limit it to screen devices (say you don;t want it for printing purposes) then you could change it to media=”screen”.

    # January 22, 2013 at 9:16 pm

    @Eric, why did you say “I disagree using css is many ways better”, can you explain it a little bit ?

    i’m still new so there’s many thing i must learn

    @paulie_d thanks for the answer

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.