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

jQuery 속성 κ΄€λ ¨ λ©”μ„œλ“œ

by oranssy 2022. 9. 5.
728x90
λ°˜μ‘ν˜•

⭐️ jQuery λ©”μ„œλ“œ ⭐️


01. jQuery 속성 κ΄€λ ¨ λ©”μ„œλ“œ

[1] attr( ) λ©”μ„œλ“œ

μ„ νƒν•œ μš”μ†Œμ˜ attribute(속성)을 선택, 생성, λ³€κ²½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ‹€ν–‰ λΆ„λ₯˜ ν˜•μ‹
취득 $("a").attr("href");
생성, λ³€κ²½ $("a").attr("href", "https://oranssy.tistory.com/").attr("target", "_blank");
$("a").attr( { href: "https://oranssy.tistory.com/", target: "_blank" } );
콜백 ν•¨μˆ˜ $("a").attr("href", function(index, h) {
     // index λŠ” 각 a μš”μ†Œμ˜ index 0, 1, 2
     // h λŠ” 각 a μš”μ†Œμ˜ href 속성
     return attribute (속성) // 각 a μš”μ†Œμ˜ 속성을 생성 및 λ³€κ²½
});
....
<a href="http://www.daum.net" target="_blank" title="μƒˆμ°½"> λ‹€μŒ </a>
<a href="http://www.naver.com" target="_blank" title="μƒˆμ°½"> 넀이버 </a>
<a href="http://www.nate.com" target="_blank" title="μƒˆμ°½"> λ„€μ΄νŠΈ </a>

# 예제 1)


[2] prop( ) λ©”μ„œλ“œ

attr( )κ°€ html attribute(속성)에 κ΄€λ ¨λœ λ©”μ„œλ“œλΌλ©΄, prop( )λŠ” μžλ°”μŠ€ν¬λ¦½νŠΈ ν”„λ‘œνΌν‹°(property)에 κ΄€λ ¨λœ λ©”μ„œλ“œμž…λ‹ˆλ‹€.
prop( ) λ©”μ„œλ“œλŠ” μš”μ†Œμ˜ 속성을 λΆˆλ¦°κ°’ (true / false)으둜 μ œμ–΄κ°€ κ°€λŠ₯ν•©λ‹ˆλ‹€.
attr( ) λ©”μ„œλ“œλŠ” checked 속성이 μš”μ†Œμ— μΆ”κ°€λ˜κ³ , prop( ) λ©”μ„œλ“œμ˜ trueλŠ” μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ ν”„λ‘œνΌν‹°λ‘œ μ²˜λ¦¬λ©λ‹ˆλ‹€.

# 예제 2)

728x90
λ°˜μ‘ν˜•

λŒ“κΈ€