user1081577
user1081577

Reputation: 469

jquery .live to .on in jquery upgrade

I'm upgrading the jQuery on my website to jQuery v1.10.1 from 1.4.2 . I'm changing all the .live functions to .on. Now i'm having trouble with changing one of them.

function tb_init(domChunk){
    $(domChunk).live('click', function(){
        var t = this.title || this.name || null;
        var c = $(this).parent().parent().find('.quotation').html();
        var a = this.href || this.alt;
        var g = this.rel || false;
        var o = $(this);
        tb_show2(t,c,a,g,o);
        this.blur();
        return false;
    });
}

I tried changing it to:

$(document).on("click", domChunk, function() {

and:

$(document).on("click", $(domChunk), function() {

But both don't seem to work. domChunk itself is a selector like this: "#myid li" The error I get is: Uncaught TypeError: Object # has no method 'blur'

Thanks

Upvotes: 0

Views: 174

Answers (2)

YP_be
YP_be

Reputation: 731

I could be wrong, but have you tried using $(this).blur() instead of this.blur? Since it is a jQuery function...

edit: sorry I hadn't refreshed the page before answering

Upvotes: 3

Naftali
Naftali

Reputation: 146302

this is a reference to the DOM object and not to the jQuery object.

Try this instead:

$(this).blur();

or:

$(this).trigger('blur');

or in your code use o instead of $(this)

Upvotes: 4

Related Questions