Если у вас нет абсолютно никаких средств говорить когда внешняя функция изменяет класс (например, пользовательское событие, например), вы должны сделать что-то вроде этого:
$(document).ready(function(){
// Cache the required element
window.elementInQuestion = $('#element-that-changes-class');
function checkClass(){
if (window.elementInQuestion.hasClass('new-class')) {
// Trigger a custom event
$(document).trigger('elementHasClass');
// If you need the check only until the first time the class appears
// you can cancel further checks here
clearInterval(window.classCheckerInterval);
}
}
// Check if an element has class every once in a while
window.classCheckerInterval = setInterval(checkClass, 100);
$(document).bind('elementHasClass', function(){
// Your handler here
});
});
решение работало. но строка if (window.elementInQuestion.hasClass ('new-class')) работает только тогда, когда я меняю ее на if ($ ('# element-that-changes-class'). hasClass ('new-class')) – Veera