출처 : http://www.hoons.net/Board/asptip/Content/50987
jquery selector에 대해 알아보기 전 jquery가 무엇인지 먼저 확인해 보겠습니다.
jquery란 자바스크립트 함수 라이브러리라고 합니다.
즉, 자바스크립의 문법을 사용하고 CSS 선택자를 사용하며 몇 가지 확장된 기능을 가지고 문서내의
element 선택해 사용하는 것이지요
그리고 !"#$%&'()*+,./:;<=>?@[\]^`{|}~ 와 같은 메타문자를 포함할 경우 \\로 escape 처리를 해줘야합니다.
예를 들어 id=foo.bar 이라면 $("#foo\\.bar")와 같이 해야 합니다.
아래는 기본 selector, 고급위치 selector, 확장기능 selector에 대해 몇가지를 소개 하였습니다.
http://www.w3schools.com/jquery/trysel.asp?filename=trysel_basic&jqsel=p.intro,%23choose에서 제공되는
툴로 아래 내용들을 확인해 볼 수 있습니다.
http://api.jquery.com/category/selectors/를 통해 좀더 자세히 공부하면 좋을것 같습니다.
저도 하나씩 하면서 좀더 공부해봐야 겠습니다.
jquery selector에 대해 알아보기 전 jquery가 무엇인지 먼저 확인해 보겠습니다.
jquery란 자바스크립트 함수 라이브러리라고 합니다.
즉, 자바스크립의 문법을 사용하고 CSS 선택자를 사용하며 몇 가지 확장된 기능을 가지고 문서내의
element 선택해 사용하는 것이지요
그리고 !"#$%&'()*+,./:;<=>?@[\]^`{|}~ 와 같은 메타문자를 포함할 경우 \\로 escape 처리를 해줘야합니다.
예를 들어 id=foo.bar 이라면 $("#foo\\.bar")와 같이 해야 합니다.
아래는 기본 selector, 고급위치 selector, 확장기능 selector에 대해 몇가지를 소개 하였습니다.
http://www.w3schools.com/jquery/trysel.asp?filename=trysel_basic&jqsel=p.intro,%23choose에서 제공되는
툴로 아래 내용들을 확인해 볼 수 있습니다.
http://api.jquery.com/category/selectors/를 통해 좀더 자세히 공부하면 좋을것 같습니다.
저도 하나씩 하면서 좀더 공부해봐야 겠습니다.
Selector | Example | Selects |
---|---|---|
* | $("*") | All elements |
#id | $("#lastname") | The element with id=lastname |
.class | $(".intro") | All elements with class="intro" |
element | $("p") | All p elements |
.class.class | $(".intro.demo") | All elements with the classes "intro" and "demo" |
|
||
:first | $("p:first") | The first p element |
:last | $("p:last") | The last p element |
:even | $("tr:even") | All even tr elements |
:odd | $("tr:odd") | All odd tr elements |
:eq(index) | $("ul li:eq(3)") | The fourth element in a list (index starts at 0) |
:gt(no) | $("ul li:gt(3)") | List elements with an index greater than 3 |
:lt(no) | $("ul li:lt(3)") | List elements with an index less than 3 |
:not(selector) | $("input:not(:empty)") | All input elements that are not empty |
:header | $(":header") | All header elements h1, h2 ... |
:animated | $(":animated") | All animated elements |
:contains(text) | $(":contains('W3Schools')") | All elements which contains the text |
:empty | $(":empty") | All elements with no child (elements) nodes |
:hidden | $("p:hidden") | All hidden p elements |
:visible | $("table:visible") | All visible tables |
s1,s2,s3 | $("th,td,.intro") | All elements with matching selectors |
[attribute] | $("[href]") | All elements with a href attribute |
[attribute=value] | $("[href='default.htm']") | All elements with a href attribute value equal to "default.htm" |
[attribute!=value] | $("[href!='default.htm']") | All elements with a href attribute value not equal to "default.htm" |
[attribute$=value] | $("[href$='.jpg']") | All elements with a href attribute value ending with ".jpg" |
[attribute^=value] | $("[href^='jquery_']") | All elements with a href attribute value starting with "jquery_" |
:input | $(":input") | All input elements |
:text | $(":text") | All input elements with type="text" |
:password | $(":password") | All input elements with type="password" |
:radio | $(":radio") | All input elements with type="radio" |
:checkbox | $(":checkbox") | All input elements with type="checkbox" |
:submit | $(":submit") | All input elements with type="submit" |
:reset | $(":reset") | All input elements with type="reset" |
:button | $(":button") | All input elements with type="button" |
:image | $(":image") | All input elements with type="image" |
:file | $(":file") | All input elements with type="file" |
:enabled | $(":enabled") | All enabled input elements |
:disabled | $(":disabled") | All disabled input elements |
:selected | $(":selected") | All selected input elements |
:checked | $(":checked") | All checked input elements |