반응형
jQuery를 사용하여 형제 요소를 선택하려면 어떻게 해야 합니까?
이 jQuery 셀렉터를 사용하는 것을 도와줄 수 있습니까?
$(".auctiondiv .auctiondivleftcontainer .countdown").each(function () {
var newValue = parseInt($(this).text(), 10) - 1;
$(this).text(newValue);
if (newValue == 0) {
$(this).parent().fadeOut();
chat.verify($(this).parent().parent().attr('id'));
}
});
기본적으로 각 루프의 .countdown과 동일한 부모에 속하는 .bidbutton 클래스의 요소를 선택합니다.
<div class="auctiondivleftcontainer">
<p class="countdown">0</p>
<button class="btn primary bidbutton">Lance</button>
</div>
그런 다음 이 버튼에 적용합니다.
$(button here).addClass("disabled");
$(button here).attr("disabled", "");
jQuery를 사용하여 일치하는 형제를 선택합니다.
$(this).siblings('.bidbutton');
$(this).siblings(".bidbutton")
$("h2").siblings().css({"color": "blue"});
you can use
$(this).siblings(".bidbutton").addClass("disabled");
$(this).siblings(".bidbutton").attr("disabled","");
$("selector").nextAll();
$("selector").prev();
또한 Jquery 선택기를 사용하여 요소를 찾을 수 있습니다.
$("h2").siblings('table').find('tr');
특정 형제를 선택하려는 경우:
var $sibling = $(this).siblings('.bidbutton')[index];
여기서 'index'는 상위 컨테이너 내의 특정 형제자매의 인덱스입니다.
부터$(this)
에 대한.countdown
사용할 수 있습니다.$(this).next()
또는$(this).next('button')
좀 더 구체적으로.
시도 -
$(this).siblings(".bidbutton").addClass("disabled").attr("disabled", "");
또한 클래스가 아닌 이름을 가진 형제를 선택해야 할 경우 다음을 사용할 수 있습니다.
var $sibling = $(this).siblings('input[name=bidbutton]');
만약 내가 당신이 이미 (각각) 루프에 있다는 것을 올바르게 이해했다면, 당신은 항상 각 루프 안에 있는 하나의 형제 버튼을 선택하고 싶었을 것입니다.형제자매()가 배열을 반환하므로 다음과 같이 하십시오.
$(this).siblings('.bidbutton')[0]
다음 작업을 수행하여 원하는 두 가지를 모두 한 줄로 적용할 수 있습니다.
$(this).siblings('.bidbutton')[0].addClass("disabled").attr("disabled", "");
언급URL : https://stackoverflow.com/questions/7463242/how-do-i-select-a-sibling-element-using-jquery
반응형
'it-source' 카테고리의 다른 글
단추를 클릭하여 표 행의 내용 가져오기 (0) | 2023.08.29 |
---|---|
도커 컨테이너로 호스트 포트 전달 (0) | 2023.08.29 |
jQuery 위치 href (0) | 2023.08.24 |
EmptyError: 순서에 요소가 없습니다. (0) | 2023.08.24 |
jQuery를 통한 Gmail like 파일 업로드 (0) | 2023.08.24 |