$('div').mouseover(function() {
});
Iinside 기능은 우리가 이벤트 기능을 추가하는 요소가 ($ (이)). 는 어떻게 다음이 함수 내에서 확인할 수 있습니다
- 이 "DIV"가 ($ (이)) 하위 요소를 "DIV"를?
- 이 "DIV"($ (this)) 아동 요소 "DIV"whith의 높이가 300 이상입니까?
$('div').mouseover(function() {
});
Iinside 기능은 우리가 이벤트 기능을 추가하는 요소가 ($ (이)). 는 어떻게 다음이 함수 내에서 확인할 수 있습니다
$('div').mouseover(function() {
var children = $(this).children("div"); //for immediate child div
if(children.length > 0){
alert("'div' child present");
for(i=0; i < children.length; i++){
if(children[i].height() > 300)
alert("'div' with height more than 300 present");
}
});
업데이트 : children[i].css('height')
도 사용할 수 있습니다.
어린이 [i] .height()에 오류가 하나 있습니다. 이 문법은 $ (children [i])와 같은 구문으로 만 작동합니다. height() – Anton
@Anton : Hmm. 이 경우'.css ('height')'를 사용할 수 있습니다. –
함수 내부에있는 경우 this
은 DIV 요소를 참조합니다. 그런 다음 그것에 대해 더 알고 싶은 모든 것을 할 수 있습니다.
자식 DIV를 얻으려면 var childDivs = $('div',this);
을 사용할 수 있습니다.
당신은 당신의 mouseover
이벤트 코드 내에서이를 삭제할 수 있습니다 :
$(this).children('div').each(function() { // $(this) is your parent <div>
if ($(this).height() > 300) { // $(this) is the current child <div>
// Do things here...
}
});
은 수정하십시오. 네가 무엇을 요구하는지 모르겠다. –
btw, 위대한 관련 스 니펫을 많이 보시려면 http://addyosmani.com/blog/50-jquery-snippets-for-developers/ – adardesign