yerassyl
yerassyl

Reputation: 3048

focus() Jquery calls Infinite alerts

$(document).on('ready page:load', function () {
    $(document).foundation();
    var user_name_input = $('#user_name');

    user_name_input.focus(function(){
        alert('hi');
    });
});

When I focus on #user_name I get infinite alerts.

Upvotes: 0

Views: 37

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

When you do

user_name_input.focus(function(){
        alert('hi');
    });

every time a focus happens on an input, the alert is raised removing the focus.

Once you click Ok for the alert box, the focus for the input box is regained and another alert raised.

Thus, a never ending cycle of alerts and focus

Upvotes: 1

Related Questions