Jquery if data is not empty add class problem
Not sure why this doesn't work quite new with js yet. I'm trying to check if there is any data, and if there is, then it should add a hidden class, or remove it if it has no data.
$(function() {
$('#search').keyup(function() {
var followerList=$("#followerlist");
if($('#search').val() !== ""){
followerList.addClass('hidden');
}else{
followerList.removeClass('hidden');
};
$.ajax({
type: "POST",
url: "/search/",
data: {
'search_text': $('#search').val(),
'csrfmiddlewaretoken': $("input[name=csrfmiddlewaretoken]").val()
},
success: searchSuccess,
dataType: 'html'
});
});
});
function searchSuccess(data, textStatus, jqXHR)
{
$('#search-results').html(data);
}
+3
source to share
1 answer