I want to use jquery and ajax to calculate the sum of 2 numbers for exemple, but every time I try from code, the part of the code that should calculate the numbers doesn’t work, but it works in console if I paste it there. The first part of the code ( the one with extracting the numbers from another page) works even in inspect element if I look, the code is there. But the one that should calculate the sum isn’t. What the best solution for this?
$.ajax({
success: function () {
$('body').append('<span class="invisible-total-messages" style= "display: hidden;">*</span>');
parseInt($('.invisible-total-messages').load('/mesaje .msglist .errorbg').hide());
var sum = 0;
$('.invisible-total-messages .errorbg').each(function () {
sum += parseInt($(this).text());
});
if (sum !== 0) {
$('#menu .new_messages_count').html(sum);
}
}
});