开发者

Jquery Form Field Focus Change Submit Button Class

I have the following form:

<input name="q" value="" cl开发者_StackOverflowass="qa-search-field">
<input type="submit" value="Search" class="qa-search-button">

I am trying to get the submit button's class to change when the qa-search-field is active by adding the class .qa-search-button-active, and then removing it if the search form is not active, meaning the cursor is not on there and blinking.

Cant figure out how to code this in Jquery.


$(".qa-search-field").focusin(function() {
   $('.qa-search-button').addClass('.qa-search-button-active');
});

(".qa-search-field").focusout(function() {
   $('.qa-search-button').removeClass('.qa-search-button-active');
});


$('document').ready(function(){
    $('input[name="q"]').focus(function(event){
        $('input[type="submit"]).attr('class', 'qa-search-button-active');
    });


    $('input[name="q"]').focus(function(event){
        $('input[type="submit"]).attr('class', 'qa-search-button');
    });
});


How about this late solution ? :)

$(".qa-search-field").focus(function () {
    $('.qa-search-button').removeClass('qa-search-button').addClass('qa-search-button-active');
});

$(".qa-search-field").blur(function () {
    $('.qa-search-button-active').removeClass('qa-search-button-active').addClass('qa-search-button');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜