Vishal B
Vishal B

Reputation: 653

call focusout inside focusin

I am trying to call focusout event inside focusin becouse I want to use previous value from focusin event, but focusout event executes many times

$('tr #edituser').focusin(function(){
      var prev_uname = $(this).text();
      $('tr #edituser').focusout(function(){
          alert();            
      });
  });

how to do it ?

Upvotes: 0

Views: 208

Answers (2)

ˈvɔlə
ˈvɔlə

Reputation: 10272

Since you wanted to know how to 'call' the focusout event handler, here you go:

$('tr #edituser').focusin(function() {
    var prev_uname = $(this).text();
    $('tr #edituser').trigger('focusout');
});

$('tr #editUser').focusout(function() {
   alert();        
});

From the jQuery documentation of the .trigger() function.

Execute all handlers and behaviors attached to the matched elements for the given event type.

Upvotes: 1

Arif
Arif

Reputation: 1643

Each time you focusin you attach a new focusout event to `'tr #edituser'. That is why it gets called multiple times.

Try This

var prev_uname;
$('tr #editUser').on('focusin', function(){
   prev_uname = $(this).val();
   console.log(prev_uname)

});

$('tr #editUser').focusout(function(){
   alert(prev_uname);            
});

Upvotes: 1

Related Questions