Byte Friendly

Random thoughts on programming and related topics.

jQuery Chaining

| Comments

I am beginning to fall in love with jQuery. Screw you, bicycle inventors! :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function next_step() {
    // note how elegant and self-explanatory this code is.
    var cl = 'step_selected';
    $('.' + cl).removeClass(cl).next().addClass(cl);

    // Also look at previous version of the code,
    // before I remembered about chaining methods.

    // var li = $('.step_selected');
    // li.removeClass('step_selected');
    // li.next().addClass('step_selected');

    // Not as sexy, right? :-)
}

Comments