λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
JQUERY

[JQUERY] ν•„ν„° μ„ νƒμž

by _토맀토 2022. 8. 31.
728x90

Jquery : ν•„ν„° μ„ νƒμž

이번 μ‹œκ°„μ—λŠ” μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ jquery ν•„ν„° μ„ νƒμžμ— λŒ€ν•΄ μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€.πŸ˜†


#1. jquery κΈ°λ³Έ ν•„ν„° μ„ νƒμž

ν•„ν„° μ„ νƒμžλŠ” μ„ νƒμžμ— : (클둠)이 뢙은 μ„ νƒμžλ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€. λ‹€μŒμ˜ ν‘œλ₯Ό 보며 ν•„ν„° μ„ νƒμžμ˜ μ’…λ₯˜λ₯Ό μ•Œμ•„λ΄…μ‹œλ‹€!

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:even $("tr:even") tr μš”μ†Œ 쀑 짝수 ν–‰λ§Œ μ„ νƒν•©λ‹ˆλ‹€.
:odd $("tr:odd") tr μš”μ†Œ 쀑 ν™€μˆ˜ ν–‰λ§Œ μ„ νƒν•©λ‹ˆλ‹€.
:first $("td:first") 첫번째 td μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:last $("td:last") λ§ˆμ§€λ§‰ td μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:header $(":header") ν—€λ”©(h1~h6) μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:eq $("li:eq(0)") indexκ°€ 0인 li μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
**indexλŠ” 0번이 첫번째 μš”μ†Œ μž…λ‹ˆλ‹€.
:gt $("li:gt(0)") indexκ°€ 0보닀 큰 li μš”μ†Œλ“€μ„ μ„ νƒν•©λ‹ˆλ‹€.
:not $("li:not(.bg)") li μš”μ†Œ μ€‘μ—μ„œ classλͺ…이 bgκ°€ μ•„λ‹Œ li μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:root $(":root") html을 μ˜λ―Έν•©λ‹ˆλ‹€.
:animated $(":animated") μ›€μ§μ΄λŠ” μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

✏️ jQuery κΈ°λ³Έ ν•„ν„° μ„ νƒμž 예제

#2. jquery μžμ‹ ν•„ν„° μ„ νƒμž

μžμ‹ ν•„ν„° μ„ νƒμž 쀑 'child'κ°€ 뢙은 μ„ νƒμžλŠ” μš”μ†Œκ°€ 순차적으둜 λ‚˜μ—΄λ˜μ–΄ μžˆμ„ λ•Œ μ‚¬μš©μ΄ κ°€λŠ₯ν•˜λ©° 'of-type'이 뢙은 μ„ νƒμžλŠ” μš”μ†Œκ°€ 순차적으둜 λ‚˜μ—΄λ˜μ–΄ μžˆμ§€ μ•Šμ•„λ„ 동일 μš”μ†Œλ©΄ 선택이 κ°€λŠ₯ν•©λ‹ˆλ‹€.

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:first-child $("span:first-child") 첫번째 spanμš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:last-child $("span:last-child") λ§ˆμ§€λ§‰ spanμš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:first-of-type $("span:first-of-type") spanμš”μ†Œ μ€‘μ—μ„œ 첫번째 span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:last-of-type $("span:last-of-type") spanμš”μ†Œ μ€‘μ—μ„œ λ§ˆμ§€λ§‰ span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:nth-child() $("span:nth-child(2)") λ‘λ²ˆμ§Έ spanμš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
nth-child(2n)은 2, 4, 6, ...번째 μš”μ†Œλ₯Ό μ„ νƒν•˜κ³ ,
nth-child(2n+1)은 1, 3, 5, ...번째 μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:nth-last-child() $("span:nth-last-child(2)") λ§ˆμ§€λ§‰μ—μ„œ λ‘λ²ˆμ§Έ span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:nth-of-type() $("span:nth-of-child(2)") spanμš”μ†Œ μ€‘μ—μ„œ λ‘λ²ˆμ§Έ span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:nth-last-of-type() $("span:nth-last-of-child(2)") spanμš”μ†Œ 쀑 λ§ˆμ§€λ§‰μ—μ„œ λ‘λ²ˆμ§Έ span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:only-child $("div > span:only-child") div의 μžμ‹μš”μ†Œμ—μ„œ 였직 span μš”μ†Œκ°€ ν•˜λ‚˜λ§Œ μžˆλŠ” spanμš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:only-child $("div > span:only-child") div의 μžμ‹μš”μ†Œμ—μ„œ span μš”μ†Œκ°€ ν•˜λ‚˜λ§Œ μžˆλŠ” spanμš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

✏️ jQuery μžμ‹ ν•„ν„° μ„ νƒμž 예제

#3. jquery μ½˜ν…μΈ  ν•„ν„° μ„ νƒμž

λ‹€μŒμ€ μ½˜ν…μΈ  ν•„ν„° μ„ νƒμž μ’…λ₯˜μž…λ‹ˆλ‹€! 이제 쀑간정도 μ™”μŠ΅λ‹ˆλ‹€. νž˜λ‚΄λ΄…μ‹œλ‹€! πŸ˜‚

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:contains() $("p:contains('html')") p μš”μ†Œ μ€‘μ—μ„œ 'html' ν…μŠ€νŠΈλ₯Ό ν¬ν•¨ν•˜κ³  μžˆλŠ” p μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:empty $("div:empty") div μš”μ†Œ μ€‘μ—μ„œ μžμ‹μš”μ†Œκ°€ μ—†λŠ” div μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:parent $("span:parent") span μš”μ†Œ μ€‘μ—μ„œ μžμ‹μš”μ†Œκ°€ μžˆλŠ” span μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:has() $("section:has(article)") section μš”μ†Œ μ€‘μ—μ„œ article을 ν•˜μœ„μš”μ†Œλ‘œ 가지고 μžˆλŠ” section μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

✏️ jQuery μ½˜ν…μΈ  ν•„ν„° μ„ νƒμž 예제

#4. jquery 폼 ν•„ν„° μ„ νƒμž

λ‹€μŒμ€ 폼 ν•„ν„° μ„ νƒμž μ’…λ₯˜μž…λ‹ˆλ‹€! μ’€ 더 νž˜λ‚΄λ΄…μ‹œλ‹€! πŸ˜‚

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:text $("input:text") <inpun type = "text"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:password $("input:password") <inpun type = "password"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:image $("input:image") <inpun type = "image"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:file $("input:file") <inpun type = "file"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:button $("input:button") <inpun type = "button">, <button> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:checkbox $("input:checkbox") <inpun type = "checkbox"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:radio $("input:radio") <inpun type = "radio"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:submit $("input:submit") <inpun type = "submit"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:reset $("input:reset") <inpun type = "reset"> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:input $(":input") λͺ¨λ“  <input> μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:checked $("input:checked") <input> μš”μ†Œμ— ckecked 속성이 μžˆλŠ” μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:selected $("input:selected") <option> μš”μ†Œμ— selected 속성이 μžˆλŠ” μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:focus $("input:focus") ν˜„μž¬ <input> μš”μ†Œμ— ν¬μ»€μŠ€κ°€ μžˆλŠ” μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:disabled $("input:disabled") <input> μš”μ†Œμ— disabled 속성이 μžˆλŠ” μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:enabled $("input:enabled") <input> μš”μ†Œμ— disabled 속성이 μ•„λ‹Œ μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

✏️ jQuery 폼 ν•„ν„° μ„ νƒμž 예제

#5. jquery κ°€μ‹œμ„± ν•„ν„° μ„ νƒμž

λ‹€μŒμ€ κ°€μ‹œμ„± ν•„ν„° μ„ νƒμž μ’…λ₯˜μž…λ‹ˆλ‹€! λ“œλ””μ–΄ λ§ˆμ§€λ§‰ ν•„ν„° μ„ νƒμž! ν™”μ΄νŒ… 🫠🫠

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:hidden div:hidden div μš”μ†Œ 쀑 hidden인 μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.
:visible div:visible div μš”μ†Œ 쀑 visible μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

✏️ jQuery κ°€μ‹œμ„± ν•„ν„° μ„ νƒμž 예제

728x90

λŒ“κΈ€


Lucky Charms Rainbow
js
html
css