I am trying to add or remove classes to some divs. These divs should be assigned different classes depending on the value of their html. I'm not sure what I'm doing wrong but my code isn't working.
This is my code:
$.ajax({
type: 'POST',
url: 'loc/bcheck.php',
success: function(data){
tArrx = new Array(data);
},
complete: function(){
$('.bHr').each(function(){
curElm = $(this);
var bTm = curElm.html();
if ($.inArray(bTm, tArrx) !== -1){
curElm.addClass('disabled');
curElm.removeClass('available');
}
else{
curElm.addClass('available');
curElm.removeClass('disabled');
}
});
}
});
<div class="bHr">1</div>
<div class="bHr">5</div>
All values of the divs' html are caught correctly. And the function runs without errors. But I allways get the same result, value is not present in array.
'data' is 1", "2", "3", "4 and using console.log it returns ["1", "2", "3", "4"]
var bTm = curElm.html().trim();dataType: 'json'for the ajax request thentArrx = data;...