λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
JAVASCRIPT/jQuery

jQuery | ν•„ν„° μ„ νƒμž

by μ½”λ”©ν•˜μž9 2022. 8. 31.
728x90

πŸ“ 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 μš”μ†Œλ“€ 선택
:lt( ) $("li:lt(2)") indexκ°€ 2보닀 μž‘μ€ li μš”μ†Œλ“€ 선택
:not( ) $("li:not(.bg)") li μš”μ†Œ μ€‘μ—μ„œ classλͺ…이 bgκ°€ μ•„λ‹Œ li μš”μ†Œ 선택
:root $(":root") html을 의미
:animated $(":animated") μ›€μ§μ΄λŠ” μš”μ†Œ 선택

πŸ“’ 직접 μ μš©ν•˜λ©΄μ„œ μ΄ν•΄ν•˜μž !

$(document).ready(function(){
    $("tr:even").css("background", "red");
    $("tr:odd").css("background", "orange");
    $("td:first").css("background", "yellow");
    $("td:last").css("background", "green");
    $(":header").css("background", "blue");
    $("li:eq(0)").css("background", "navy");
    $("li:gt(0)").css("background", "purple");
    $("li:lt(3)").css("border", "4px solid gray");
    $(":root").css("background", "lightgray");
    (function upDown(){
      $("h2").slideToggle(2000, upDown);
    })();
    $(":animated").css("border", "4px solid darkred");
});

πŸ“‚ μžμ‹ ν•„ν„° μ„ νƒμž

'child'κ°€ 뢙은 μ„ νƒμž : μš”μ†Œκ°€ 순차적으둜 λ‚˜μ—΄λ˜μ–΄ μžˆμ„ λ•Œ μ‚¬μš©ν•©λ‹ˆλ‹€.
'or-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) : 2, 4, 6, ...번째 μš”μ†Œ 선택
:nth-last-child( ) $("span:nth-last-child(2)") λ§ˆμ§€λ§‰μ—μ„œ 두 번째 span μš”μ†Œ 선택
:nth-of-type( ) $("span:nth-of-type(2)") span μš”μ†Œ μ€‘μ—μ„œ 두 번째 span μš”μ†Œμ„ νƒ
:nth-last-of-type( ) $("span:nth-last-of-type(2)") span μš”μ†Œ 쀑 λ§ˆμ§€λ§‰μ—μ„œ 두 번째 span μš”μ†Œ 선택
:only-child $("div > span:only-child") div의 μžμ‹ μš”μ†Œμ—μ„œ 였직 span μš”μ†Œκ°€ ν•˜λ‚˜λ§Œ μžˆλŠ” span μš”μ†Œ 선택
:only-of-type $("div > span:only-of-type") div의 μžμ‹ μš”μ†Œμ—μ„œ span μš”μ†Œκ°€ ν•˜λ‚˜λ§Œ μžˆλŠ” span μš”μ†Œ 선택

πŸ“’ 직접 μ μš©ν•˜λ©΄μ„œ μ΄ν•΄ν•˜μž !

$(document).ready(function(){
    $("#m1 > span:first-child").css("border", "2px solid red");
    $("#m1 > span:last-child").css("border", "2px solid red");
    $("#m2 > span:first-of-type").css("border", "2px solid orange");
    $("#m2 > span:last-of-type").css("border", "2px solid orange");
    $("#m3 > span:nth-child(1)").css("border", "2px solid yellow");
    $("#m3 > span:nth-last-child(1)").css("border", "2px solid yellow");
    $("#m4 > span:nth-of-type(1)").css("border", "2px solid green");
    $("#m4 > span:nth-last-of-type(1)").css("border", "2px solid green");
    $("#m5 > span:only-child").css("border", "2px solid blue");
    $("#m6 > span:only-of-type").css("border", "2px solid navy");
});

πŸ“‚ μ½˜ν…μΈ  ν•„ν„° μ„ νƒμž

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

πŸ“’ 직접 μ μš©ν•˜λ©΄μ„œ μ΄ν•΄ν•˜μž !

$(document).ready(function(){
    $("#m1 > p:contains('html')").css("border", "4px solid red");
    $("#m1 > p:empty").css("border", "4px solid orange");
    $("#m2 > span:parent").css("border", "4px solid yellow");
    $("#m3 > section:has(article)").css("border", "4px solid green");
});

πŸ“‚ 폼 ν•„ν„° μ„ νƒμž

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

πŸ“’ 직접 μ μš©ν•˜λ©΄μ„œ μ΄ν•΄ν•˜μž !

$(document).ready(function(){
    $("input:text").css("background", "red");
    $("input:password").css("background", "\orange");
    $(":button").css("background", "yellow");
    $("input:checked + label").css("background", "green");
    $("option:selected").css("color", "blue");
    $("textarea:disabled").css("background", "pink");
});

πŸ“‚ κ°€μ‹œμ„± ν•„ν„° μ„ νƒμž

μ„ νƒμž μ’…λ₯˜ μ„€λͺ…
:hidden div:hidden div μš”μ†Œ 쀑 hidden인 μš”μ†Œ 선택
:visible div:visible div μš”μ†Œ 쀑 visible인 μš”μ†Œ 선택

πŸ“’ 직접 μ μš©ν•˜λ©΄μ„œ μ΄ν•΄ν•˜μž !

$(document).ready(function(){
    console.log($("div:hidden").text());
    $("div:visible").css("background", "orange");
});

'JAVASCRIPT > jQuery' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

jQuery | 클래슀 λ©”μ„œλ“œ  (2) 2022.09.04
jQuery | 탐색 μ„ νƒμž  (8) 2022.08.31
jQuery | 속성 μ„ νƒμž  (9) 2022.08.30
jQuery | κΈ°λ³Έ μ„ νƒμž  (11) 2022.08.30
JAVASCRIPT | jQuery  (8) 2022.08.29

λŒ“κΈ€


It's cording time

μ½”λ”© μ—¬κΈ°μ„œ μ •λ¦¬ν•˜κ³  λ°°μ›Œλ³΄μžκ΅¬ :9

κ΄‘κ³  μ€€λΉ„μ€‘μž…λ‹ˆλ‹€.