요소의 클래스 속성이 변경되면 JQuery 코드를 실행해야한다. 예를 들어 처음에는 요소는 <div class="my-class">
이됩니다. 새로운 클래스가이 사업부에 추가 될 때, (즉, <div class="my-class new-class">
, 나는 JQuery와 코드를 실행해야합니다. 나는 JQuery와이 작업을 수행하려면 어떻게요소의 클래스 속성을 변경하기위한 Jquery 이벤트
? 이벤트 속성에 대한 있는가 변경?
요소의 클래스 속성이 변경되면 JQuery 코드를 실행해야한다. 예를 들어 처음에는 요소는 <div class="my-class">
이됩니다. 새로운 클래스가이 사업부에 추가 될 때, (즉, <div class="my-class new-class">
, 나는 JQuery와 코드를 실행해야합니다. 나는 JQuery와이 작업을 수행하려면 어떻게요소의 클래스 속성을 변경하기위한 Jquery 이벤트
? 이벤트 속성에 대한 있는가 변경?
, 당신은 이런 식으로 뭔가를해야 할 것 : 할 수 없습니다
$(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
});
});
을 기능을 결합 그것은 DOM이 주기적으로 변화를 찾고 검색과 의지합니다 변경 사항이 발생하면 이벤트를 발생시킵니다.
외부 함수 (예를 들어, 같은 사용자 정의 이벤트를) 클래스를 변경하면 당신이 이야기의 전혀 방법이없는 경우
용액을 사용 하였다. 하지만 if (window.elementInQuestion.hasClass ('new-class')) if if ($ ('element-that-changes-class'). hasClass ('new-class'))로 변경하면 if – Veera