Fuxi
Fuxi

Reputation: 7599

jQuery: bind another event to object

i've made a textbox widget which will highlight onFocus (and "un-highlight" onblur). my question: i'd like to append another event to the blur-event AFTERWARDS which will eg. display a messsagebox.

i know i can assign multiple events with bind but i'd need to add that extra event after bind was already assigned.

how would this be possible?

thanks

Upvotes: 0

Views: 735

Answers (1)

Eli
Eli

Reputation: 17825

If you are wanting to bind after blur has triggered:

$('.myelement').blur(function() {

    $(this).bind('mycustomevent', function() {
        // code here
    });

});

If you are wanting to bind right after blur has bound:

$('.myelement')
    .blur(function() {
        // code here
    })
    .bind('mycustomevent', function() {
        // code here
    });

If you want to trigger the SAME functionality with blur AND your custom event:

$('.myelement').bind('blur mycustomevent', function() {
    // code here
});

jQuery Binding: http://api.jquery.com/bind/

Upvotes: 1

Related Questions