We can add or remove a class to an element very easily by using addClass() and removeClass() methods. To do this on keyup event of a textbox we just need call these functions when we bind keyup event to textbox.
Example:
<input id="search-box" type="text" placeholder="search city...."/>
<input type="button" id="search-submit" value="Search" />
$(function(){
$("#search-box").on("keyup", function(){
if($("#search-box").val() == ""){
$('#search-submit').addClass("not-active-search");
} else {
$('#search-submit').removeClass("not-active-search");
}
});
});
Hope this will help you :)
0 Comment(s)