...

jQuery CSS ์ ํ์ ๋ชจ์
๊ธฐ๋ณธ ์ ํ์
์ ํ์ | ์์ | ์ค๋ช |
* | $("*") | ๋ชจ๋ ์์๋ฅผ ์ ํ |
.class | $(".class") | ์ง์ ํ ํด๋์ค๋ฅผ ๊ฐ์ง๋ ๋ชจ๋ ์์๋ฅผ ์ ํ |
element | $("element") | ์ง์ ๋ ํ๊ทธ๋ช ์ ๊ฐ์ง๋ ๋ชจ๋ ์์๋ฅผ ์ ํ |
#id | $("#id") | ์ง์ ํ ID ์์ฑ์ ๊ฐ์ง๋ ํ๋์ ์์๋ฅผ ์ ํ |
, | $("selector1, selecotr2") | ๋ชจ๋ ์ง์ ํ ์ ํ์๋ค์ ๊ฒฐ๊ณผ๋ค์ ๊ฒฐํฉํ์ฌ ์ ํ |
โ
์์ ์ ํ์ (child)
์ ํ์ | ์์ | ์ค๋ช |
:first-child | $("div:first-child") | ๋ถ๋ชจ์ ์ฒซ ๋ฒ์งธ ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:first-of-type | $("div:first-of-type") | ๋์ผํ ์์ ์ด๋ฆ์ ํ์ ์ค ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๋ชจ๋ ์ ํ |
:last-child | $("div:last-child") | ๋ถ๋ชจ์ ๋ง์ง๋ง ํ์ ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:last-of-type | $("div:last-of-type") | ๋์ผํ name ์์์ ํ์ ์ค ๋ง์ง๋ง ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:nth-child(index/even/odd/equation) | $("div:nth-child(2)") | ๋ถ๋ชจ์ n ๋ฒ์งธ ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:nth-last-child(index/even/odd/equation) | $("div:last-child(2)") | ๋ง์ง๋ง ์์์์ ์ฒซ ๋ฒ์งธ ์์๊น์ง ๊ณ์ฐํ์ฌ ๋ถ๋ชจ์ n ๋ฒ์งธ ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:nth-last-of-type(index/even/odd/equation) | $("div:nth-last-of-type(2)") | ๋ง์ง๋ง ์์๋ถํฐ ์ฒซ ๋ฒ์งธ ์์๊น์ง ๊ฐ์ name ์์๋ฅผ ๊ฐ์ง ํ์ ์ ๊ด๋ จํ์ฌ ๋ถ๋ชจ์ n ๋ฒ์งธ ์์์ธ ๋ชจ๋ ์์ ์ ํ |
:nth-of-type(index/even/odd/equation) | $("div:nth-of-type(2)") | ๋์ผํ name ์์๋ฅผ ๊ฐ๋ ํ์ ์ ๊ด๋ จํ์ฌ ๋ถ๋ชจ์ n๋ฒ์งธ ์์์ธ ๋ชจ๋ ์์ ์ ํ |
:only-child | $("div:only-child") | ๋ถ๋ชจ์ ์ ์ผํ ์์์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:only-of-type | $("div:only-of-type") | ๋์ผํ name ์์๋ฅผ ๊ฐ๋ ํ์ ๋ ธ๋๊ฐ ์๋ ๋ชจ๋ ์์ ์ ํ |
โ
๊ณ์ธต ์ ํ์ (Hierarchy)
์ ํ์ | ์์ | ์ค๋ช |
> :: parent > child | $("ul > li") | "parent"๋ก ์ง์ ๋ ์์์ "child"๋ก ์ง์ ๋ ๋ชจ๋ ์ง์ ์์ ์์ ์ ํ |
(๊ณต๋ฐฑ) :: ancestor descendant | $("form input") | ์ง์ ๋ ์กฐ์์ ์์์ธ ๋ชจ๋ ์์ ์ ํ |
+ :: prev + next | $("label+input") | ํ์ "prev"๊ฐ ๋ฐ๋ก ์์ ์ค๋ "next"์ ์ผ์นํ๋ ๋ค์ ์์ ๋ชจ๋ ์ ํ |
~ :: prev~siblings | $("#prev~div") | "prev"์์ ๋ค์์ ์ค๋ ๋ชจ๋ ํ์ ์์๋ฅผ ์ ํํ๊ณ , ์์ ์์๊ฐ ๊ฐ์ผ๋ฉฐ ํํฐ๋ง "siblings" ์ ํ์์ ์ผ์นํ๋ ์์ |
โ
์์ฑ ์ ํ์ (Attribute)
์ ํ์ | ์์ | ์ค๋ช |
[attribute|='value'] | $("[name|=apple]") | ์์ฑ name๊ฐ์ด apple์ด๊ฑฐ๋, apple- ์ผ๋ก ์์ํ๋ ์์ |
[attribute*='value'] | $("[name*=apple]") | ์์ฑ name๊ฐ์ด apple์ด๋ ๋จ์ด๋ฅผ ํฌํจํ๋ ์์ (์ด๋ ์์น๋ ) |
[attribute~='value'] | $("[name~=apple]") | ์์ฑ name๊ฐ์ด apple์ด๊ฑฐ๋ apple ๊ณต๋ฐฑ / ๊ณต๋ฐฑ apple ์ผ๋ก ๊ตฌ๋ถ๋ ๋จ์ด๋ฅผ ํฌํจํ๋ ์์ |
[attribute$='value'] | $("[name$=apple]") | ์์ฑ name๊ฐ์ด apple์ด๊ฑฐ๋ apple๋ก ์ ํํ ๋๋๋ ๊ฐ์ธ ์์ ๋น๊ต๋ ๋์ ๋ฌธ์๋ฅผ ๊ตฌ๋ถํจ. |
[attribute='value'] | $("[name=apple]") | ์์ฑ name๊ฐ์ด ์ ํํ apple์ธ ์์ |
[attribute!='value'] | $("[name!=apple]") | ์์ฑ name๊ฐ์ด apple์ ์์ ๊ฐ์ง ์๊ฑฐ๋, apple ์ด์ธ์ ๊ฐ์ ๊ฐ์ง ์๋ ์์ |
[attribute^='value'] | $("[name^=apple]") | ์์ฑ name๊ฐ์ด apple์ด๊ฑฐ๋, apple๋ก ์ ํํ ์์ํ๋ ์์ |
[attribute] | $("[name]") | ์์ฑ name์ ๊ฐ๊ณ ์๋ ์์ |
[attribute='value'][attribute2='value2'] | $("[name=apple][name2=banana]") | ๊ฐ ์์ฑ ์ ํ์๋ค์ด and๋ก ์ผ์นํ๋ ์์ |
<inuput type="text"/>
<script>
$('input[type=text]').val("ํ
์คํธ ๊ฐ์ถ๊ฐ");
</script>
์์ฑ ์ ํ์ ์ฐ์ตํด๋ณด๊ธฐ
์ฐ์ธก์ ์ ํ์ ๋ฒํผ์ ๋๋ฌ ์ด๋ ๋ฌธ์์ด์ด ํด๋น๋๋์ง ์๋ณํ ์ ์๋ค.
jQuery ์ ์ฉ ์ ํ์ ๋ชจ์
jQuery์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ณตํต์ผ๋ก ์ฐ์ด๋ CSS ์ ํ์ ๋ฟ๋ง ์๋๋ผ ๋ช๋ช ์ ์ด์ฟผ๋ฆฌ ์ ์ฉ ๋นํ์ค ์ ํ์๋ ์ง์ํ๋ค
๊ธฐ๋ณธ css ์ ํ์๋ก๋ ๋ถ์กฑํ์ฌ ์ฌ์ฉ์ ํธ์์ฑ์ ์ํด ์ ์ด์ฟผ๋ฆฌ์์ ์์ฒด์ ์ผ๋ก ์ถ๊ฐํ ์ ํ์ ๋ฌธ๋ฒ์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค.
์ด๋ฌํ ๋นํ์ค ์ ํ์๋ฅผ ์ฌ์ฉํ๋ฉด ์ ํํ ์์๋ฅผ ์ ์ฅํ๊ฑฐ๋, ๊ทธ ๊ฒฐ๊ณผ์ ๋ํด ํํฐ๋ง๊น์ง ํ ์ ์๋ค.
โ
๊ธฐ๋ณธ ํํฐ ์ ํ์(Basic Filter)
์ ํ์ | ์์ | ์ค๋ช |
:odd | $("div:odd") | ํ์ ๋ฒ์งธ์ ์์นํ ๋ฌธ์ ๊ฐ์ฒด๋ฅผ ์ ํํจ |
:even | $("div:even") | ์ง์ ๋ฒ์งธ์ ์์นํ ๋ฌธ์ ๊ฐ์ฒด๋ฅผ ์ ํํจ |
:first | $("div:first") | ์ฒซ ๋ฒ์งธ ์์นํ ๋ฌธ์ ๊ฐ์ฒด๋ฅผ ์ ํํจ |
:last | $("div:last") | ๋ง์ง๋ง์ ์์นํ ๋ฌธ์ ๊ฐ์ฒด๋ฅผ ์ ํํจ |

์ ํ์ | ์์ | ์ค๋ช |
:root | $("div:root") | document์ ๋ฃจํธ ์์ ์ ํ |
:target | $("div:target") | document์ URL์ flagment ์๋ณ์๋ก ์ง์ ๋ ๋์ ์์๋ฅผ ์ ํ |
:header | $("div:header") | h1, h2, h3 ๋ฑ๊ณผ ๊ฐ์ด ํค๋์ธ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:empty | $("div:empty") | ์์์ด ์๋ ๋ชจ๋ ์์(ํ ์คํธ ๋ ธ๋ ํฌํจ)๋ฅผ ์ ํ |
:parent | $("div:parent") | ํ๋ ์ด์์ ํ์ ๋ ธ๋(์์ ๋๋ ํ ์คํธ)๊ฐ ์๋ ๋ชจ๋ ์์๋ฅผ ์ ํ |
โ
ํจ์ ํํฐ ์ ํ์(function Filter)
์ ํ์ | ์์ | ์ค๋ช |
:eq(index) | $("div:eq(1)") | ์ผ์นํ๋ ์งํฉ ๋ด์ ์ธ๋ฑ์ค n์ ์๋ ์์๋ฅผ ์ ํ |
:gt(index) | $("div:gt(2)") | ์ผ์นํ๋ ์ธํธ ๋ด์ ์ธ๋ฑ์ค๋ณด๋ค ํฐ ์ธ๋ฑ์ค์์ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:lang(language) | $("div:lang(en-us)") | ์ง์ ๋ ์ธ์ด์ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:lt(index) | $("div:lt(4)") | ์ผ์นํ๋ ์งํฉ ๋ด์ ์ธ๋ฑ์ค๋ณด๋ค ์์ ์ธ๋ฑ์ค์์ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:not(selector) | $("div:not(:checked)") | ์ง์ ๋ ์ ํ์์ ์ผ์นํ์ง ์์ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:contains(text) | $("div:contains('Hello'") | ์ง์ ๋ ํ ์คํธ๋ฅผ ํฌํจํ๋ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:has(selector) | $("div:has(p)") | ์ง์ ํ ์ ํ์์ ์ผ์นํ๋ ์์๋ฅผ ํ๋ ์ด์ ํฌํจํ๋ ์์๋ฅผ ์ ํ |
:animated | $("div:animated") | ์ ํ์๋ฅผ ์คํํ ๋ ์ ๋๋ฉ์ด์
์งํ ์ํ์ ์๋ ๋ชจ๋ ์์๋ฅผ ์ ํ ":not(:animated)" => ์ ๋๋ฉ์ด์ ์ค์ด์ง ์์๊ฒ |
โ
์ ๋ ฅ ์์ ํผ(Form) ํํฐ ์ ํ์
์ ํ์ | ์์ | ์ค๋ช |
:button | $(":button") | input ํ๊ทธ์ค type ์์ฑ์ด button์ธ ๋ฌธ์ ๊ฐ์ฒด์ button ํ๊ทธ๋ฅผ ์ ํ |
:checkbox | $(":checkbox") | ์ฒดํฌ๋ฐ์ค ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:checked | $(":checked") | ์ฒดํฌ๋๊ฑฐ๋ ์ ํ๋ ๋ชจ๋ ์์์ ์ผ์นํ ์์ ์ ํ |
:disabled | $(":disabled") | ๋นํ์ฑํ๋ ๋ชจ๋ ์์ ์ ํ |
:enabled | $(":enabled") | ํ์ฑํ๋ ๋ชจ๋ ์์ ์ ํ |
:file | $(":file") | ํ์ผ ์ ํ์ ๋ชจ๋ ์์๋ฅผ ์ ํ |
:focus | $(":focus") | ํ์ฌ ํฌ์ปค์ค๊ฐ ์๋ ์์ ์ ํ |
:image | $(":image") | ์ด๋ฏธ์ง ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:input | $(":input") | ๋ชจ๋ input, textarea, select, button ์์ ์ ํ |
:password | $(":password") | ํจ์ค์๋ ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:radio | $(":radio") | ๋ผ๋์ค ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:reset | $(":reset") | reset ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:selected | $(":selected") | ์ ํ๋ ๋ชจ๋ ์์ ์ ํ |
:submit | $(":submit") | submit ์ ํ์ ๋ชจ๋ ์์ ์ ํ |
:text | $(":text") | text ์ ํ์ ๋ชจ๋ input ์์ ์ ํ |
<select>
<option>์ฌ๊ณผ </option>
<option>๋ธ๊ธฐ </option>
<option>์๋ฐ </option>
<option>๋ฉ๋ก </option>
</select>
<script>
$('select > option:selected').val(); // select ๋ก ์ ํ๋ ๊ฐ์ด ์ฐพ๊ธฐ
</script>
โ
๊ฐ์์ฑ ํํฐ ์ ํ์ (Visibility Fileter)
์ ํ์ | ์์ | ์ค๋ช |
:hidden | $("div:hidden") | hidden ๋ ๋ชจ๋ ์์ ์ ํ |
:visible | $("div:visible") | visible์ธ ๋ชจ๋ ์์ ์ ํ |
# ์ฐธ๊ณ ์๋ฃ
https://poiemaweb.com/jquery-basics
https://hane-1.tistory.com/33
https://hane-1.tistory.com/36
์ด ๊ธ์ด ์ข์ผ์ จ๋ค๋ฉด ๊ตฌ๋ & ์ข์์
์ฌ๋ฌ๋ถ์ ๊ตฌ๋
๊ณผ ์ข์์๋
์ ์์๊ฒ ํฐ ํ์ด ๋ฉ๋๋ค.