버튼 요소 (클래스 없음) 아래에있는 경우에만 클래스 "bar"로 선택하는 데 사용할 jQuery 선택기가 "foo"클래스가있는 div 아래에 있는지 알고 싶습니다.
<div class="foo">
<button>
<i class="bar">X</i>
...
".foo button.bar"가 작동하지 않습니다.
편집 됨 : 모든 솔루션에 감사하고 솔루션을 시도했지만 어떤 이유로 다음도 선택됩니다.
<div id="mceu_36" class="mce-widget mce-btn mce-first" tabindex="-1" aria-labelledby="mceu_36" role="button" aria-label="Align left">
<button role="presentation" type="button" tabindex="-1">
<i class="mce-ico mce-i-dashicon dashicons-align-left"></i>
</button>
</div>
...
<div id="mceu_40" class="mce-widget mce-btn" tabindex="-1" aria-labelledby="mceu_40" role="button" aria-label="Edit ">
<button role="presentation" type="button" tabindex="-1">
<i class="mce-ico mce-i-dashicon dashicons-edit"></i>
</button>
</div>
내 의도는 <i>
mce-first가있는 div 아래에있는 경우에만 dashicons-edit 클래스로 클릭을 처리 하는 것입니다. 위의 예에서 "mce-first"는 형제 div에 있습니다.
요구 사항을 명시 적으로 준수하려면 :
<i>
클래스 "bar"로 선택이 선택기를 원할 것입니다.
div.foo > button:not([class]) > i.bar
선택기 구문에서 공백은 DOM 계층 구조 아래의 모든 수준을 나타냅니다. >
연산자는 직접 아이를 나타냅니다.
직접 자식 선택을 원하지 않는 경우 공백을 사용하십시오.
div.foo button:not([class]) i.bar
(이외의 <button>
) 요소에 특별히 관심이없고에 있는 클래스가 무엇인지 상관하지 않는 <button>
경우 다음을 사용하십시오.
.foo button .bar
선택자는 class 가있는 요소 아래의 모든 수준 .foo button.bar
에있는 <button>
with 클래스 bar
를 찾고 있었습니다 foo
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다