[Day3] jQuery 3 [12/1]
jq DOM μ‘°μ
μμ μ½κ² μμΈμ€, μ‘°μ(μμ±, μμ , μμ , μ΄λ λ±λ±) - DOM κ΄λ ¨ λ©μλ
DOM - html, xml λ¬Έμμ μμΈμ€ νκΈ° μν νμ€ μ μ
1) jq DOM method :
val() input value μ€μ , λ°ν value
text() <μ>ν μ€νΈ</μ’ > html X μ€μ , λ°ν innerText
html() <μ>ν μ€νΈ</μ’ > html O μ€μ , λ°ν innerHTML
2) μμ± λ°ν, μ€μ
attr()
prop()
is()
<input type="text" id="name" value="<b>admin</b>">
<br>
<button>νμΈ</button>
<p id="demo"></p>
<hr>
<!-- http://www.sist.co.kr -->
<a href="#">sist</a>
<script>
// $(document).ready(function (){});
$(function (){
// $("a").href
// $("a").prop("href", ??)
// $("a").attr("href", "http://www.sist.co.kr");
// href μμ± μ€μ + alt μμ±
$("a").attr({
"href":"http://www.sist.co.kr",
"alt":"test",
"title": "μμ©κ΅μ‘μΌν°"
});
});
</script>
<script>
// js
/*
document.querySelector("button").onclick = function (){
//document.getElementById("demo").innerText
document.getElementById("demo").innerHTML
= document.getElementById("name").value;
}
*/
</script>
<script>
// jq
// $(selector).action();
$("button").click( function (){
// $("#demo").text( $("#name").val() );
// $("#demo").html( $("#name").val() );
$("#name").val( "xxx" );
});
</script>
[ jq μμ μΆκ° ] ex03_02.html
append() / appendTo() λΆλͺ¨.append(μμ) , μμ.appendTo(λΆλͺ¨)
prepend() / prependTo()
before()
after()
[ jq μμ μΆκ° ]
remove() μ νν μμλ₯Ό μ κ±°
empty() μ νν μμμ μμ μμλ₯Ό μ κ±°
[ js μμ μΆκ° ]
var p = document.createElement("p");
appendChild( p )
removeChild( p );
p.remove();
insertBofore()
[jq CSS μ‘°μ]
1. css()
2. addClass()
3. removeClass()
4. toggleClass()
5. hasClass() true/fasle
[jq μμ, μλμ° ν¬κΈ°]
1. width()
2. height()
3. innerWidth()
4. innerHeight()
5. outerWidth()
6. outerHeight()
[λλΉ(width)]
margin border padding [content] padding border margin
10px 2px 5px 5px 2px 10px
jq width() |<- ->|
jq innerWidth() |<- ->|
jq outerWidth() |<- ->|
jq outerWidth(true) |<-
jq νμ(Traversing(ν‘λ¨))
- μ¦μ‘°λΆλͺ¨
γ΄ μ‘°λΆλͺ¨
γ΄ λΆλͺ¨
γ΄ μμ, + μμ ... ( νμ )
γ΄ μ¦μμ + μ¦μμ ..
[ λΆλͺ¨ νμνλ jq λ©μλ ]
parent()
parents()
parentsUntil()
jquery νμ( μμ )
- children() : μ νν μμμ λͺ¨λ μ§κ³ μμμ λ°ν
- find() : μ νν μμμ λͺ¨λ νμ(νμ)μ λ°ν
1. μ‘°μ νμ
parent(), parents(), parentsUntil()
2. νμ νμ
children(), find()
3. νμ νμ
siblings()
next() / prev()
nextAll(), nextUntil()
prevAll(), prevUntil()
4. νν°λ§
first()
last()
not()
eq()
filter()
jQuery νλ μμν¬ μ¬μ© + λ€λ₯Έ νλ μμν¬ ν¨κ» μ¬μ©.
$ κΈ°νΈ $ κΈ°νΈ [ μΆ©λ ]
jQuery("p")
μλ X
=> jquery method : noConflict() λ©μλλ₯Ό μ¬μ©ν΄μ μΆ©λ ν΄κ²°..
// js κ°μ²΄μμ±μ - κ°μ²΄λ₯Ό μμ±ν λ μ¬μ©λλ ν¨μ , λλ¬Έμλ‘ ν¨μλͺ μμ.
// days08 ν΄λ jquery-3.6.1.js 164 λΌμΈ
jQuery.fn = jQuery.prototype = {
// The current version of jQuery being used
jquery: version,
constructor: jQuery,
:
}
// κ°μ²΄ μμ±μλ‘ μμ±, λ©μλ μΆκ°
// Person.prototype.μμ±λͺ
// Person.prototype.λ©μλλͺ = function (){}
wrap() / unwrap()
κ°μΈλ€(ν¬μ₯νλ€)
[ jq μ΄λ²€νΈ λ±λ‘ ]
on() jquery Ajax ( κΈ°μ΅ )
one() μ΄λ²€νΈ νλ²λ§ λ±λ‘.
off()
each() κ²μ
1) 컬λ μ μ‘°μ : each()
2) μ νΈλ¦¬ν° : jQuery.each()
μ΅κ·ΌλκΈ