본문 바로가기

Local Oriented/jQuery

this 와 $(this), 디스 DOM Object

jQuery 에서 ..

this 는 단일 개체(Object), 단일 요소(Element).

$(this)는 DOM 구조에서의 복수 구성원(Element). 단일 Element 라도 배열 형태로 담김.


- $(this) 가 하나의 DOM Element 라고 가정한다면,

this 는 $(this).get(0) 또는 $(this)[0] 와 동일

$(this).get(n) == $(this)[n]

cf. $('...').toArray()


- 역으로 생각해 보면. 단수를 복수 개념으로 끌어 들이기 위해 해당 요소를 $() 로 둘러 싸면 됩니다.

   $(this) 를 단수로 잡았다가 다시 jquery 함수를 먹이기 위해 $() 로 둘러싸는 거죠.

   $(this) == $($(this).get(0)) == $($(this)[0])


- Element 배열이다 보니 이런 방법도 가능 $('#..').toArray()[0] 

http://pgm-progger.blogspot.com/2011/11/js-jquery-html-dom.html


- this.tagName 과 this.name 은 <input name="inputA" ... /> 라고 할때 tagName 은 "input" 이고 name 은 "inputA" 라는 것.


- $(this) 의 반대는 아마도, $(this).parent().children().not(this)

var $o = $('...');

$o.bind('click',function(){

  $o.not(this).함수명1();

  $(this).함수명2();

});

'Local Oriented > jQuery' 카테고리의 다른 글

append() 와 appendTo()  (0) 2012.08.09
[모음글] toggle  (0) 2012.08.09
[모음글] attr 속성  (0) 2012.08.08
jQuery 플러그인, Vanity. 슬라이더, 탭, 팁, 페이지, 스팟라잇 등등  (1) 2012.07.09
[모음글] Type  (0) 2012.07.06