March 28, 2012

Delegate for jQuery 1.3.2

Question by estrar

I got this code today that works for jQuery v7. The problem is that it need to work for 1.3.2 as well. How would I translate it?

$(document).ready(function() {
    $("ul#dropdown li ul").hide(); 
    $("ul#dropdown").delegate( 'li', 'click', function () {   
    if (!$(this).parent().is("ul#dropdown") ) {
            return false; 
        }  
    $(this).siblings('.' + "current").removeClass("current").children('ul').slideUp('fast');
    $(this).addClass("current").children('ul').slideDown('fast')
    });
});

Answer by Starx

The only option for delegation in 1.3 is live() method

$("ul#dropdown li").live('click', function () {   
    if (!$(this).parent().is("ul#dropdown") ) {
            return false; 
        }  
    $(this).siblings('.' + "current").removeClass("current").children('ul').slideUp('fast');
    $(this).addClass("current").children('ul').slideDown('fast')
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!