2
내가 원하는 어떤 텍스트 노드가없는 경우는 <img />
이 포함되어 있지만 텍스트 문자열을 포함하지 않는 경우에만 jQuery를가 <a>
에 diog-fail
의 class
을 추가 , 또는 텍스트 문자열을 포함하는 다른 HTML 요소. 2 개의 예는 다음과 거짓 같습니다jQuery를 : 그것은 이미지를 포함하는 요소에 클래스를 추가하지만,
<a href="#">
<img width="100" height="100" alt="alternative text" src="some/location/image.gif" />
Some text
</a>
<a href="#">
<img width="100" height="100" alt="alternative text" src="some/location/image.gif" />
<span>Some text</span>
</a>
다음 예제는 jQuery를이 class
diog-fail
의 적용 것이다 :
<a href="#">
<img width="100" height="100" alt="alternative text" src="some/location/image.gif" />
</a>
중요 : 텍스트의 문자열 아무것도 될 수 있습니다.
최고, 않습니다 내가 필요 정확히! 감사. – DigiKev
+1 : 멋진 솔루션! – naveen
@DigiKev - 천만에요. @yetanothercoder - 감사합니다! – karim79