Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery live - focusin fires multiple times

Tags:

jquery

I am using JQuery 1.4.1. I have HTML input elements which created dynamically. I have assigned "focusin" event all input elements. While loading page, it is triggers only once while focusing each input element.

Problem is, When I minimize and maximize the page, focus event is fired multiple times. Finally it show "Stack overflow at line 0".

   $('input').live("focusin",function(objectRef) {
        alert("focusin event");

    })

What could be causing this problem?

like image 676
user263444 Avatar asked Feb 01 '10 11:02

user263444


1 Answers

Don't worry. It only happens when you call alert(). But I don't really understand why clicking the OK button on the alert box will trigger the event multiple times.

Try this instead and it will only fires once, as expected.

$('input').live("focusin",function(objectRef) {
    //alert("focusin event");
    $("#some_div").append('focus!');
})

Same as focus, click, and other events.

like image 170
kenfai Avatar answered Nov 01 '22 23:11

kenfai