glen maxwell glen maxwell - 4 years ago 140
Javascript Question

How do toggle click event with focusout in jquery

I am having form with couple of text boxes with focus in and focus out event.I am unable to fire click events on buttons because focus out event called once I lost writing from textboxes.How do fire click event to just after focus out.

$(document).on("focusout", ".fn-enlargeTextarea", function(event) {
var optionNumber = ($(this).attr('id').replace('1option','')).trim();
$('#1option'+optionNumber+'_counter').remove();
$(this).removeClass('textarea-height01').addClass('textarea-height02');
});

Answer Source

you could use event.relatedtarget

   $(document).on("focusout", ".fn-enlargeTextarea", function(event) {
     var optionNumber = ($(this).attr('id').replace('1option','')).trim();
     $('#1option'+optionNumber+'_counter').remove();
     $(this).removeClass('textarea-height01').addClass('textarea-height02');  
     var targetEvent = event.relatedTarget;
     $(targetEvent).click();
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download