focus() jQuery function doesn't work in Safari, but works fine on all other browsers?

Posted by pMan on Stack Overflow See other posts from Stack Overflow or by pMan
Published on 2010-06-14T14:41:10Z Indexed on 2010/06/14 16:02 UTC
Read the original article Hit count: 156

Filed under:
|
|
|
|

I have a search text field and search button, when button is clicked with default text in text field, or null value, an alert pops up and sets focus back on search text field. This works very well on all major browsers but not in safari.

I tried it even with out jquery, but didn't work. When the focus falls on search text field, I have another jQuery function, is that the problem.

The code that sets focus on search text is:

if (defaults.keyword == SEARCH_TIP || defaults.keyword == '') {
    alert(SEARCH_NULL);
    $('#store_search_keyword').focus();
    return false;
}

The code on focus is:

var search_dom = $('#store_search_keyword');
var search_text = search_dom.val();
search_dom.focus(function(){
    if ($(this).val() === SEARCH_TIP) {
        $(this).val('');
    }
});

any help is appreciated, thanks..

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery