19

I am trying to convince those who set standards at my current organization that we should use jQuery rather than Prototype and/or YUI. What are some convincing advantages I can use to convince them?

2
  • 3
    Everyone and their mom uses it. :P Sep 16, 2008 at 6:12
  • 3
    JQuery is just a DOM manipulator, YUI is a component framework with a DOM manipulator included.
    – Kdeveloper
    Sep 22, 2010 at 18:14

18 Answers 18

24

The 3 main advantages of jQuery are:

  • its light weight when compared to other javascript frameworks
  • it has a wide range of plugins available for various specific needs
  • it is easier for a designer to learn jQuery as it uses familiar CSS syntax. jQuery is Javascript for Designers
0
14

I would say my top reasons for using JQuery are:

  • Large development community and many plugins.
  • It's on Microsoft's radar and they are adding some plugin support and debug capabilities.
  • Very good documentation for a 3rd party library.
  • Lightweight.
  • Chaining capabilities are very powerful.
1
  • Not just Microsoft's radar - also Google's radar. Aug 18, 2012 at 15:32
6

In my opinion, having briefly tried Prototype, and then later trying and loving jQuery: the jQuery API just feels much cleaner and well thought out. John Resig, the creator/architect of jQuery really knows his stuff, and it shows in the design of jQuery, as well as the various other impressive JavaScript projects that he has been a part of.

The whole concepts of querying and chainability fit very well with DOM manipulation, which seems to be the brunt of what people use JS libraries for. The online documentation is fantastic. Performance seems to be very good as well. The entire library fits into a relatively small package given it's capabilities. The plugin architecture is also very nice for extensibility.

I honestly haven't tried YUI, so I can't comment much on that. I do know that it is a rather massive library in total, though you can choose to download/use only specific modules of it.

6

Here's a more recent speed test than the one provided above. Last time I ran it dojo was the fastest followed by jQuery, Mootools, Prototype, and finally YUI. Note I ran it in Firefox 3 and the speeds vary between browsers so test it out yourself.

Slick Speed Test

1
  • 3
    This is not a recent speed test, nor is it comprehensive. Slick Speed compares CSS selector engines, not overall performance. YUI 2.5.2 was released in 2008. The current production version of YUI 2.x is 2.8.2, with 2.9 in the works. It will be the last dot release on the 2.x code line. YUI 3 has been available since 2009. The current version version is 3.2, and 3.3.0 will ship in January 2011.
    – Luke
    Dec 29, 2010 at 4:55
6

It's the most well thought out language you'll find -- it's almost intuitive.

Want an element's width?

$('#something').width();

Want to grab an element, hide it, change its background color and fade it back in?

$('#something').hide().css('background', 'red').fadeIn();

How about table striping for IE (assuming hover class is defined)?

$('table tr').hover(function() {
  $(this).addClass('hover');
});

It's quick, mindless work like this that really helps sell jQuery.

4

One advantage of jQuery is the large community which has developed a multitude of plugins.

4
  1. It's very small, especially when minified, and offers a lot in the core library.

  2. It's also easy to extend, and has an active community.

  3. Finally, it's extremely easy to learn; once you've grasped the core concepts you can start coding complex solutions right away.
4

One argument in favor is this:

popularity + extensibility

1) If anyone needs to do X with JavaScript, it's probably been done with jQuery
2) If it's been done much, there's probably a plugin, if not native support

And if it's really unique, there are a lot of people to answer your question on SO or elsewhere.

3

You can follow this link to know more about jQuery, why to use it and what are it's advantages are.

2

Empirically each has their own strengths and weaknesses given a very specific role within your applications. Making a global determination may not be the most appropriate approach. Carve out the specific task at hand and analyze performance, bloat, experience etc then make a specific decision / proposal.

2

Well...

First you should think about why you think jQuery is good but you don't know what arguments to use to convince another. Perhaps you should convince yourself first. ;)

Anyway, jQuery is just another framework. You should use for what it does best. If your going to use it just for basic DOM handling, forget it! learn how to use js properly and you will be fine!

Consider this HTML:

<body>
<div style="width: 400px; height: 400px; background-color: red">
<div style="width: 400px; height: 400px; background-color: red">
</div>

<script type="text/javascript">

function test1 (){
document.body.innerHTML = ""

var div = document.createElement("div");

document.body.appendChild(div);

$(div).width("400px").height("400px").css("background-color", "red");
}    

function test2 (){
document.body.innerHTML = ""

var div = document.createElement("div");

document.body.appendChild(div);

$(div).width("400px");
$(div).height("400px");
$(div).css("background-color", "red");
}

function test3 (){
document.body.innerHTML = ""

var div = document.createElement("div");

document.body.appendChild(div);

div.style.width = "400px";
div.style.height= "400px";
div.style.backgroundColor = "red";
}

function test4 (){
    document.body.innerHTML = ""

    var div = document.createElement("div");

    document.body.appendChild(div);

    div.setAttribute("style", "width: 400px; height: 400px; background-color: red");
}

</script>
</body>

Put it in a hml file with jquery available in <head>

Then, open firebug and run this code: console.profile(); test1(); console.profileEnd();

console.profile();
test2();
console.profileEnd();

console.profile();
test3();
console.profileEnd();

console.profile();
test4();
console.profileEnd();

See the results for your self!

But if you want do some complex manipulation on the DOM that would require you to make several loops or find out with elements on the DOM match some criteria, you can consider to use jQuery since it will implement this procedures for you.

Anyway, keep in mind that there is nothing better than controlling the DOM with references you keep in your code. Its faster and more readable to others. Google "js best practices".

I use jQuery for complex things that it would take me too long to implement and would end up with something like jQuery's code. In that case, it makes sense to use it!

Have fun!

1

I am a Prototype person, but I've used jQuery a bit. Honestly I don't there is much between the two that you can use as a 'selling point'. The YUI on the other hand is pretty bloated. I would never use it on any commercial grade application.

I found this page that talks about this exact subject.

2
1

Maybe you shouldn't? It all depends on what kind of application(s) you're building. If you are building GUI intensive applications, something like, say, Yahoo! Mail, then maybe you should consider using YUI or Mootools over jquery. Personally I'm a huge jQuery fan, but it is definitely best for adding a touch of interaction to an otherwise mostly static UI. On the other hand, if that is what you'll be using it for, then jquery is a lot simpler, has nicer syntax, and it has a lot of momentum.

1

It has a good set of plugins and the coding style is unobtrusive which means it's not too hard to replace. There is also a nice drop in replacement for Ruby on Rails helpers called jRails.

Performance-wise they are all pretty close: http://www.kenzomedia.com/speedtest/ However, MooTools, dojo, ext, and Prototype all run faster in my environment.

My question is- why do you want to use it? Is it just because you know it better?

1
  • Good question! I want to use it because I think it has better syntax, more features available (when you include plug-ins), excellent documentation, and MUCH stronger community support. But we already have a company standard, so I thought I'd look for extra ideas to bolster my argument.
    – mcherm
    Sep 16, 2008 at 20:04
1

Jquery has been around for a few years, so like everyone else has said, it has a deep community, lots of plug-ins, and decent support. What set it aside for me was that it's easy to learn.

See http://visualjquery.com/1.1.2.html

1

I have been using jQuery for a few months now and have found it an enjoyable experience. The framework is clear and concise it has a great plugin architecture and is very well supported but frameworks are a very personal thing though and you should probably try a few it doesn't normally take long to spot the one that feels best for you.

Not sure if this will matter to you but Microsoft recently announced support for jQuery in the next update for VS 2008 Here is the blog post.

You can hear the John Resig, the guy behind jQuery, talking about it a various other frameworks on a recent Boagworld podcast. It might help you make up your mind its a pretty balanced piece.

0

Why don't you create a quick comparison?

Take a task like "find all divs or tables which contain images of class foo and attach a click event to each of them which makes them expand 50%." Or something more relevant to what you're doing.

Then code that with jQuery, Prototype, etc, and compare. Which is shorter? Easier to read? Faster to run? (You can find a speed comparison here.)

1
  • I'd go with a less arbitrary test case. How about: make an AJAX call to an external script and place the response into a styled message box in the middle of the screen.
    – nickf
    Sep 15, 2008 at 21:55
0

If you are trying to convince people from a business perspective, Microsoft's recent decision to ship jQuery with Visual Studio could help establish some additional credibility. Then again, that could hurt your cause, depending on their opinions of Microsoft.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.