Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Good/Bad practice.

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #41008
    Chester
    Participant

    Is it a good practice to inline all CSS properties in your jQuery? or just add the class using jquery and put all the CSS properties directly on the style.css?

    Like when you’re adding a HTML element via jQuery and you want to style it.

    I like to ask for opinions because a buddy of mine is teaching me that it is not good to inline all those CSS into your jQuery script. I’m having doubts on it because I’m adding the HTML element(eg: div overlay for the page)., and I think all the extra CSS code directly included in my stylesheet will be just be a waste when Javascript is disabled.

    I’m not really sure.

    Hope you understand what I’m asking.

    Thanks guys.

    #115563
    Chester
    Participant

    @joshuanhibbert,
    So what do you think about this one. [Append Site Overlay DIV](https://css-tricks.com/snippets/jquery/append-site-overlay-div/ “Append Site Overlay DIV”).
    Thanks.

    #115566
    Chester
    Participant

    OK. Thanks. Now I can go on.
    Anymore tips or links for good practices on JS and jQuery.

    @joshuanhibbert
    , thanks a lot really.

    #115567
    Chris Coyier
    Keymaster

    Yeah keep CSS in CSS as much as you can for sure. Don’t be too dogmatic about it though. There are always cases where certains ways of doing things make sense. In the case of that snippet – it does what it says on the box. In general though, I’d move that style out of the JavaScript and into the CSS.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.