2012-02-05 2 views
1

두 개의 버튼 중 하나는 "버튼 흰색"클래스이고 다른 하나는 "버튼 흰색 작은"클래스입니다. jQuery에서 하나의 버튼을 클릭 할 때마다 텍스트가 두 개의 버튼으로 바뀌고 있습니다.중복 클래스에 작용하는 jQuery 텍스트

$(document).ready(function() { 
$(".button.white").click(function() {      
    $('.button.white').text('Added'); 
    }); 
}); 

어떻게 피할 수 있습니까?

답변

2
$(".button.white").click(function() {      
    $(this).text('Added'); 
}); 
1

당신은 클릭 된 버튼을 가져 this을 사용할 수

$(document).ready(function() { 
    $(".button.white").click(function() { 
     $(this).text('Added'); 
    }); 
}); 
0

출발점을, 나는 시도 할 것이다 :

$(document).ready(function() { 
    $(".button.white").click(function() {      
    $('.button.white').not(".small).text('Added'); 
    }); 
}); 

가 .small 항목을 제거합니다. 이 모든 단어가 diffrent 클래스라고 생각 렸기 때문에

(체크되지 않은, 내가 ATM을 테스트 할 수있는 권한이 없기 때문에.)

1

이 발생합니다. 클래스를 버튼 - 흰색 및 버튼 - 흰색 - 작게 '(공백없이) 및 코드에 기입하십시오.

$(".button-white").click(function() {      
    $(this).text('Added'); 
});