How do I use jQuery sortable?

Should I use jQuery or just plain JavaScript?

  • I recently started reading jQuery: Novice to Ninja (http://www.sitepoint.com/books/jquery1/) and in the second paragraph of chapter 1, there is a sentence that reads "To conquer the sleeping giant that is JavaScript, you just need to buckle down and spend the next few years learning about programming languages: functions, classes, design patterns, prototypes, closures..." and then it goes on to say that the alternative is learning jQuery. This struck me as odd for one main reason: I've studied computer science for years and I'm very, very familiar with functions, classes, design patterns, prototypes, and closures. I've written very little JavaScript myself, but if you hand me a JavaScript file, I can look through it and figure out what it does in 30 seconds. JavaScript is just like any other programming language, just with different syntax. Since I'm already an experienced computer programmer, should I bother to learn jQuery, or should I just focus on getting really good with JavaScript? That line in the book I mentioned above really makes it seem like jQuery is designed for non-programmers. I hate WYSIWYG HTML and CSS editors because I'm good at writing those two by hand; am I going to hate jQuery because I'm good at crafting code by hand?

  • Answer:

    You are right to think that the quote is odd.  The reason is clear: jQuery is JavaScript.  Learning jQuery doesn't obviate the need to learn JavaScript.  Someone who fully understands JavaScript and its nuances will write better code when using the jQuery library than someone who doesn't. The problem I see is that many people (presumably including the author of the book you cited) confound JavaScript, the programming language, with the DOM API provided by web browser runtimes.  From a programmer's perspective, the DOM is a horrible API with leaking abstractions all over the place (subjective, I know**).  When you converse with people complaining about plain-jane JavaScript, it helps to dig a bit deeper and more often than not, you'll discover that they're really complaining about the DOM API which is orthogonal to JavaScript. jQuery's role in the whole matter is to provide a better DOM API -- somewhat of a fluent interface / internal DSL on top of it -- not to fix or replace shortcomings of JavaScript as a whole. For folks who don't understand the distinction I'm trying to make, I highly recommend Douglas Crockford's book JavaScript: The Good Parts. ** It bugs me to leave such a subjective statement in place without explanation.  One of the marks of a good API is that it has a high expressive power to cognitive weight ratio.  That is, proverbially, simple things should be simple and complex things should be possible.  The DOM API, in my opinion, is certainly expressive, but carries a high cognitive weight; complex things are possible, but simple tasks are often more complex than they need to be.  The value of using jQuery (or other such DOM wrapping libraries) is that they reduce the cognitive weight required for doing such simple tasks: e.g. referencing elements by ID, by class, by other attributes, attaching event handlers, dynamically manipulating the DOM structure, and so on.  All of those things can be done using the DOM API directly but your code will carry a much higher cost in terms of what you have to keep in your head as opposed to a well-designed wrapper API like jQuery.

Joe Holloway at Quora Visit the source

Was this solution helpful to you?

Other answers

The reason that sentence says what it says is that JavaScript does all of those things... slightly differently than most people would expect.  And, only in the context of an abstract conversation about, for example, the differences between how classes work in most languages and how they're handled in JavaScript, can you really MASTER JavaScript. jQuery throws a blanket of more conventional programming over all of that, which makes it really useful but also obfuscating at the same time. I fully recommend learning BOTH - JavaScript first, then jQuery.  Otherwise, you'll be using a tool you don't fully understand.

Paul Reiber

It's the same case with me. I do prefer to use javascript instead of jquery/mootools. As I fear all the abstraction that jquery or any other library does, Whereas coding in js assures me that am in control. But, it's hard to ignore the pros of using a library, largely because it save the development time, when dealing with DOM manipulation. Just check out http://www.awwwards.com/ to know for yourself. Each of the websites featured are competent in design and elegance, thanks to libraries such as jquery .Be it scrolling on the single page webapps or parallax, jquery is upfront in these business, just because a developer just does not have to deal with quirky dom elements for all the effects. At the same time, it's important to know js since, it could save you from being cornered when dealing with unexpected use cases when using jquery. Also, js is fun to learn. Check out Douglas crockford's book : Javascript: The Good  Parts. JS has it's flaws, but once you get the hang of it, you would be juggling between functional and object-oriented paradigms. (the functional part is cool). So, In short, use libraries when you want to create complex ui stuff which involve complicated dom manipulation and use js (the language, not it's dom functions), when you want to have fun using closures, prototypal inheritance, self-invoking functions and write some beautiful functional stuff. Note: there's also coffeescript if you feel uncomfortable with js.

Vignesh Anand

jQuery is a JavaScript library. At some point you will have to learn JavaScript. jQuery is written in JavaScript.

Josh Edrington

Learning JavaScript is like learning another computer programming language with different set of syntax and libraries, but learning jQuery is like learning a Framework based on a known programming language. So it'll be completely your call; if you know PHP would you not want to learn Zend or Symphony or CakePHP or any other Framework or CMSs like Drupal? If you know Ruby would you want to learn Ruby on Rails? I don't think you would hate jQuery at all because if you wish you can craft amazing pieces of code out of it.

Kamalika Guha Roy

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.