1

I am trying to attach a focusin event on a future element using jquery 1.5.2. Just to clarify,this has also been attempted using jQuery 1.7.2 with the same issue.

The event is not firing as i expected it to. Yet a similar click event works correctly using .live

I've put together an example here for you to take a look at my code. Hopefully this will not been a simple issue (although it always seems to be!).

Link to jsfiddle

This is my focusin event i am trying to attach

$(".active").live("focusin", function() {
    $(this).text("focusin using live");
});

I believe i have found some related questions, but im unable to fix my code using them. I would prefer an explanation over a "here is your code corrected answer".

If you think i need to add more information to my question please leave a comment.

Related

jQuery focusin and focusout live events are not firing

Why the "focusin" event handler isn't called?

Community
  • 1
  • 1
Undefined
  • 11,234
  • 5
  • 37
  • 62

1 Answers1

1

You need to focus the element if you expect the focusin event to trigger. The fact that you are applying a DOM element the .active class doesn't mean that you are focusing it.

$('.active').live('focusin', function() {
    $(this).text('focusin using live');
});

$('.active').focus();
​

Here's a demo.

Another thing you will notice is that .live() supports the focusin event starting from jQuery 1.7.1. Obviously in this version of jQuery, .live() is deprecated and you should use .on():

$(document).on('focusin', '.active', function() {
    $(this).text('focusin using on');
});

$('.active').focus();

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928