jQuery - Javascript 2.0

For those of you working with javascript without jQuery, Im sorry. After getting to know jQuery with several projects, Im a convert and never going back. To take a peek, head over to jQuery Home. Their documentation is great, but let me show you a common task that is really a breeze with jQuery.



Example 1: onMouseOver / out



Everyone has had to do the onMouseOver(dothis), onMouseOut(doThat). Well, jQuery has a nice built in function called hover. You use it like this:


$("td").hover(
function () {
$(this).addClass("hover");
},
function () {
$(this).removeClass("hover");
}
);


Lets break this down. The 1st part: $("td") invokes the query like portion of jQuery, and is called the selector. This is saying find any element in my DOM of the class td, then apply the hover attributes too it. The 1st function is run when you mouse into your td, and the 2nd when you mouse out, with some internal controls to ensure you dont get that annoying flicker. You can also see the addClass() and removeClass() functions, which do exactly like you would think, adding or removing classes from the results of your selector (all the tds).

I really think you owe it to yourself to check out jQuery. With some of the best documentation of any javascript library out there, small download, and tons of features and addons, its the best thing Javascript has going.
Digg StumbleUpon Facebook Technorati Fav newsvine reddit FARK Google Bookmarks
  1. Rey Bango

    #1 by Rey Bango - March 6, 2008 at 10:19 AM

    Welcome to the club. There's a # of jQuery/CF developers out there so be sure to join us on the jQuery mailing list.
  2. webexpertise

    #2 by webexpertise - April 1, 2009 at 1:24 PM

    It's good to know plain JavaScript, I really recommend getting a good idea of how plain javascript works before you jump to use any of the awesome framework/libraries out there, it will make things much easier to understand.
    Jquery is definately my first choice but I also like prototype. Just try not to mix them in one page, it tends to get frowzy.

Comments are closed.