user2274359
user2274359

Reputation: 25

addClass() during only for some second

After some problems with jquery ui autocomplete, I would like create my autocomplete text, I would like ask you: Why addClass() is not persistent? Add class persist for few seconds and auto remove.

i=0;
$(document).keyup('a', function (e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    if ($('#suggerimenti_ricerca').is(':visible')){
        if(keycode==40){
            i = i+1;
            if(document.getElementById('sugg_ric_'+i) == null){
                i = i-1;
                return;
            }
            $('#sugg_ric_'+i).addClass('sugg_hover');

        }else if(keycode==38){
            i = i-1;
            if(document.getElementById('sugg_ric_'+i) == null){
                i = i+1;
                return;
            }
            $('#sugg_ric_'+i).addClass('sugg_hover');
        }
    }
});

jsFiddle

Upvotes: 0

Views: 158

Answers (2)

user2274359
user2274359

Reputation: 25

Problem:

<input type="text" id="search_box" onkey**up**="compilazione_automatica();" />

Resolution:

<input type="text" id="search_box" onkey**down**="compilazione_automatica();" />

Thanks to all.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129792

addClass does not auto-remove classes after some delay. I would assume that you're adding a class to an element that is being overwritten.

Upvotes: 3

Related Questions