开发者

Need Help Converting JQuery .delegate to .live

开发者 https://www.devze.com 2023-01-23 02:26 出处:网络
I am working on script where I have code like this... $(document).delegate(scroll.links,\'c开发者_如何学编程lick\',function(){

I am working on script where I have code like this...

$(document).delegate(scroll.links,'c开发者_如何学编程lick',function(){
            switchTo(getId(this.href))
            return false
        })

I want to convert it into .live I tried but couldnt get it right.

Can anybody show me ?

Thanks.


You can do it this way:

$('scroll.links').live('click', function(){
   switchTo(getId(this.href));
   return false;
});

However, it is important to know the difference between the two:

  • Difference between delegate and live


From reading the docs, I imagine it would be something like this:

$(scroll.links).live("click", function() {
    switchTo(getId(this.href))
    return false
})

Note: I have not tested this. I successfully use delegate() in some of my own code; the docs suggest that delegate() is actually more powerful and more flexible.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号