Somebody
Somebody

Reputation: 9645

jQuery access some obj from callback

return this.each(function(){

    $(this).mouseenter(s,function(){

        s.self = $(this);
        s.slot = $(this).attr('id').split('_')[1];

        s.callback = function(o){
            var s = {}
            $.extend(s,o);

            /* Ajax call, to get banner info data */                        
            s.ajax = $.getJSON(domain+lng+'/banner/countbanners?slot='+s.slot,function(data){

                s.template = $.tmpl(s.name,$.extend(data,{
                    slot_width:s.self.width(),
                    slot_height:s.self.height(),
                    view_href:s.view_href+s.slot
                }));
                s.template.appendTo(s.self);

            });

        }

        $.get_template(s);

    });

    $(this).mouseleave(s,function(o){
        s.self.find('.banner_info_wr').remove();
    });

});

How can i access s.ajax object inside mouseleave?

Callback is called inside get_template function, after it gets template.

Thanks ;)

Upvotes: 0

Views: 92

Answers (1)

Jan Hančič
Jan Hančič

Reputation: 53931

Define s outside of your mousenter (inside the each callback) and you will be able to access it.

Upvotes: 1

Related Questions