This is my code:
function getBlock2(EUID, MID, I, ESTS)
{
$('.new-exam').on('click', function() {
$('.new-exam').removeClass('new-exam');
$(this).addClass('new-exam-hover');
$('.tab-item-hover').addClass('tab-item');
$('.tab-item').removeClass('tab-item-hover');
});
$('.tab-item').on('click', function() {
$('.new-exam-hover').addClass('new-exam');
$('.new-exam').removeClass('new-exam-hover');
$('.tab-item-hover').removeClass('tab-item-hover');
$(this).addClass('tab-item-hover');
});
$.ajax({
type: "POST",
url: './exam/x/exams_ajax.exe.php',
data: { EUID : EUID, MID : MID, I : I, ESTS : ESTS },
cache: false,
success: function(data) {
$('.block2').html(data);
}
}); return false;
}
On the first click, the ajax part works, but the remove/addClass one doesn't until I click again.
I can't seem to figure out why, any help would be appreciated. Thanks.
I would suggest add document.ready
as suggested by others and then check if you are doing in below order.
getBlock2
function definedgetBlock2
functionAs a best practice, always refer your js files at the end of your page.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments