Reputation: 1056
I have the following form:
<input name="q" value="" class="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.
Upvotes: 0
Views: 1225
Reputation: 1518
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');
});
Upvotes: 0
Reputation: 5824
$('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');
});
});
Upvotes: 2
Reputation: 17750
$(".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');
});
Upvotes: 2