I heart jQuery

Earlier this year, my manager asked me to research Javascript framework to be used in our applications.

I proposed jQuery since it seems to be getting lots of love around CF community. Another reason (quite selfishly) was: I want to learn another framework and growing my repertoire of skills (if I wanted to play it safe, I'd recommend Prototype and Scriptaculous since I have used them quite a lot on previous position).

I knew it was a good bet proposing jQuery but man, I just realized how amazing it is coding in jQuery.

Yesterday, I was re-writing a piece of javascript validation. Basically the code is meant to check a multi select field, it needs to find out whether the selected options is between 1 to 4. So below is the comparison on how would you find the number of options selected in a multi select using non framework approach and jQuery approach.

The old plain (read pain) javascript:

var CareerOne_type_id=document.getElementById('CareerOne_type_id');
var CareerOneTotal=0;

for (var i=0; i <e;CareerOne_type_id.options.length; i++) {
    if(CareerOne_type_id.options[i].selected) {

The new code in jQuery:

var CareerOneTotal = $.map($('#CareerOne_type_id :selected'), functon(e) { return $(e).text(); }).length 

I love it! It’s so beautiful.. 

I almost wish that I do lot more jQuery and less ColdFusion :)