컴퓨터 공부/자바스크립트

[jquery] jquery selectors [2] (:not, :hidden,[attribute=value], :selected, eq(index) )

나정_ 2013. 1. 16. 11:00

jquery selector 두번째 글이다. 


오늘은 :not , eq, :hidden, :input, :checked, :selected 에 대해서 정리해보도록 하겠다. 


:not (selector)


1.parameter : selector 대상 element에서 제외시킬 selector 


2,return : arrayt<elements> 


3.description : 일치하는 element 들 중 not에 해당되는 element를 제외한 element를 리턴한다. 


4. 예시





::hidden(selector)


1,return : arrayt<elements> 


2.description : input element의 type속성 값이 hidden으로 되어이쓴 모든 element를 가르킨다. 또한 display가 none으로 되어있는 경우도 리턴할 수 있다. 


3. 예시 





* attr(찾기원하는 속성명) 으로 이용하여 해당 속성명을 가지고 있는 element의 속성값을 리턴한다. 

ex) 위의 예제를 보고 끈어서 설명하자면  

$($(""input:hidden").get(0))  = input element의 type 속성 값이 hidden으로 되어있을 떄 첫번째 배열값을 리턴해라 

$($(""input:hidden").get(0)).attr("name") = 리턴한 값의 name 속성명을 가지고 있는 속성 값을 리턴하라는 의미이다.  


이러한 방식처럼 input 값 타입 속성(:button,  : reset , : iamge, : file ,:password 등) 에 들어가는 것들을 위와 유사하게 사용할 수 있다. 

예제) checked ( ex: $(input:checked)         

                                   

[attribute=value]

1. parameter : attribute:(string) : element속성명 
                      value: (string) 속성값

2. return : Array<Element> 
3. description : 대상 element에서 속성 명과 속성값이 입력 값과 같은 element를 리턴한다. 
4. 예제 



결과값은 하늘이가 나온다. 


selected 


1. return : Array<Element> 
2. description : select- element에서 선택된 (selected) option-element를 선택한다. 
3. 예제

eq(index)


1. parameter (Number) : 선택할 element의 index (0부터 시작) 
2. return : element 
3. description : 대상 element 중 입력받은 index에 해당하는 element를 리턴한다. 입력값에 해당하는 index가 존재하지 않을 경우 빈 문자열을 리턴한다.