:selector
을 jQuery에서 다음과 함께 사용할 수 있습니까?
$('.galler_attr').bind('click', function() {
$(this:first-child).css('color', 'red');
});
:selector
을 jQuery에서 다음과 함께 사용할 수 있습니까?
$('.galler_attr').bind('click', function() {
$(this:first-child).css('color', 'red');
});
아니요. 함수 컨텍스트를 문자열과 혼합하려고합니다.
선택기의 context로 사용 this
또는 요소의 DOM 범위 내에서 검색 $(this)
에 find()
를 호출합니다. 어느 (내부적으로 위에서 해결)
$('.galler_attr').bind('click', function() {
$(this).find(':first-child').css('color', 'red');
});
나이 :
$('.galler_attr').bind('click', function() {
$(':first-child', this).css('color', 'red');
});
thx 많이, 매우 도움이 !! – hoerf
을 경우에, 나는 궁금 .is()
$('.galler_attr').bind('click', function() {
$(this).is(':first-child').css('color', 'red');
// this would change the color to red if the clicked element is a first-child....
});
사용하는 이유뿐만 아니라 1 세대에 바인딩 아이를 직접?
$('.galler_attr:first-child').bind('click', function() {
// this would bind click event to the first-child element...
$(this).css('color', 'red');
});
예, 사용할 수는 있지만 그렇게 할 수는 없습니다. 러스가 말했듯이 그것을 넣을 수 있습니다.
$('.galler_attr').bind('click', function() {
$(this).find(':first-child').css('color', 'red');
});
www.visualjquery.com으로 이동하면 더 쉽게 문제를 해결할 수 있습니다. 꽤 예쁘다.
클릭 된 요소의 첫 번째 하위 항목을 찾고 있거나 클릭 된 요소가 상위 항목의 첫 번째 하위 항목인지 확인하고 싶지는 확실하지 않습니다. 제발 좀 더 명확하게 해줄 수 있니? –