SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Silver Springs, NY
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why Use Javascript?

    From seeing all the cool things you can do with Javascript and doing some coding of my own, can anyone tell me why I should use it over CSS? What are the advantages to it? Should I really sit down and try to understand it that much, or should I just keep using CSS to do what seems to be the same exact thing? Granted, there are a few things that can only be done with Javascript, but is it really worth it?

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Granted, there are a few things that can only be done with Javascript
    A few things !?

    You completly mix 2 different things.
    CSS is for setting display rules, and that only.

    Javascript can alter CSS rules on the fly, but it can go miles further than that.
    Javascript is used to add scripting behavior to your pages. React upon users actions, and ease the interaction with the server by doing some processing locally.

    It's like saying that looking through the glass of an aquarium is the same than diving into the titanic.

    Try to create on the fly text with css, and come back when you succeed. It will mean that CSS3 will a bit more supported.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    HTML: Content
    CSS: Presentation
    JavaScript: Behaviour

    Those are the three fundamentals of web design.
    Understanding Progressive Enhancement
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    HTML defines your page content.

    CSS defines your page appearance.

    JavaScript defines your page behaviour.

    Trying to use CSS to define page behavious would be like trying to drive to work in your bed rather than your car. Each should be used for the purpose it is intended for.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Silver Springs, NY
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, Yes, Yes! I know and agree about the 3 layers and everything. Allow me to be a bit more specific. I do not know everything to Javascript at this point in time. This causes me to shy away from it at times. For example, I know how to make a navigation bar in both CSS and Javascript, but when I come about to do it, I use CSS. It's easier for me and seems to work just as fine. I get the same rollover effects and can get the correct page to be highlighted when active. Is this still wrong to do? I know that there are right and wrong times to use Javascript, due to loading times and such. I just don't know when or what these times are. Hope this helps me explain things a little better!

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    In that case then, it can be better for navigation to be performed by css because javascript is less likely to be available than css.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript is NOT an alternative to CSS, it's a programming language, one which is used to add behaviour to web pages, such as form validation, interactive content etc.

    I know how to make a navigation bar in both CSS and Javascript
    This makes no sense.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  8. #8
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Silver Springs, NY
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All these questions arose when I read an article on how to make a nav bar with Javascript. It made me start to wonder why you would do this instead of CSS. I also read the articles in the following links. So I thought I would ask around for some additional input on what to think.
    http://www.sitepoint.com/article/int...oug-crockford/

    http://www.sitepoint.com/blogs/2004/05/28/using-javascript-for-presentation/

  9. #9
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Silver Springs, NY
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What everyone has been telling me is great! It made me think of this old article I read back when I first came about writing code. Good stuff! What I would really like to hear more about is what everyone uses Javascript for. Do you have a favorite form that you like to put on a lot of your sites? Do you think Javascript is over or under-used? Is there something you do with Javascript constantly that you survive without it? Just personal preferences and opinions.

  10. #10
    SitePoint Addict zipperz's Avatar
    Join Date
    Nov 2008
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like javascript for roll over buttons it is easy and works great, a lot of people have been raving that css is better for rollovers I looked into it once and it just seemed like a hassle so I just stick with the java, it is so simple in Dreamweaver.

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    I use javascript to improve the user's experience. Without javascript the page can be quite functional, but with it things like correcting errors on form submissions become a lot easier for the user.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Member
    Join Date
    Jun 2008
    Location
    Silver Springs, NY
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like javascript for roll over buttons it is easy and works great
    I use CSS for this. Is there a right/wrong way for things like this?
    W. W.

  13. #13
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cow8boi8 View Post
    I use CSS for this. Is there a right/wrong way for things like this?
    It's debatable because a rollover state (hover state) could strictly be categorised as a behaviour but since CSS usually == maximum support people tend to stick with it.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •