[Day2] jQuery 2 [11/30]
--๋ณต์ต--
๊ฐ์ ์ฝ๋ฉ
$(document).ready(function (){
});
$(function (){
});
$( jq selector).action();
[jquery ํจ๊ณผ ]
- ์จ๊ธฐ๊ธฐ, ํ๊ธฐ, ํ ๊ธ , ์ฌ๋ผ์ด๋, ํ์ด๋ , ์ ๋๋ฉ์ด์ ... ๋ฑ๋ฑ
- hide(), show()
๋ชจ๋ pํ๊ทธ ์จ๊ธฐ๊ธฐ
<button>show</button>
<button>toggle</button>
<!-- p*5>lorem5 -->
<p>1. Lorem ipsum dolor sit amet.</p>
<p style="display: none;">2. Sunt hic repudiandae sed reiciendis!</p>
<p>3. Nulla ab nobis ea reprehenderit?</p>
<p style="display: none;">4. Deserunt nam enim ut accusamus.</p>
<p>5. Minima sunt amet perferendis excepturi.</p>
<script>
$(function (){
$("button").last().click(function (){
// show() -> hide()
// hide() -> show()
// ํ ๊ธ ๊ธฐ๋ฅ
$("p").toggle(600);
} );
});
</script>
<script>
$(function (){
// css selector -> jquery selector + ์ํ
//$("button:nth-of-type(1)")
//$("button:first-of-type")
//$("button:eq(0)")
// $("button").first().click( function (){
$("body").find("button").eq(0).click( function (){
// alert("2")
// ๋ชจ๋ p ํ๊ทธ
// $("p").hide();
// $("p").hide(400);
$("p").hide("slow" , function (){
alert("์จ๊ธฐ๊ธฐ ์๋ฃ!!")
}); // "fast"
});
});
</script>
* ๋ฒํผ ์ฐพ๊ธฐ ๋ง์ ๋ฐฉ๋ฒ์ด ์์
<a href="http://www.daum.net">daum</a>
// ์์ daum ๋งํฌํ๊ทธ๋ฅผ ํด๋ฆญํ ๋
// ๊ทธ ๋งํฌ ํ๊ทธ๋ฅผ ์จ๊ฒจ๋ผ..
// a ๋งํฌ ํ๊ทธ์ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ด ํ์ด์ง ์ด๋.(์ฐ๊ฒฐ)
$("a").click( function (event){
// $(this).href = "#";
// this.href = "#"; // (๊ณ ๋ฏผ) href ์์ฑ X
event.preventDefault(); // ( ๊ธฐ์ต )
// submit
$(this).hide();
});
* ๋งํฌ๋ฅผ ์๋จน๊ฒํ๊ณ hide (#์ผ๋ก ๋๊ฑฐ๋ event.preventDefault()๋ ๊ฐ๋ฅ)
+fade, fadeTo, slidedown, slideup, slidetodggle, animate(์ ๋๋ฉ์ด์ ํ ์ ๊ณต),
(jquery days02 ์ฐธ๊ณ )
์ฝ๋ฐฑํจ์ : ์์ ํ ์ฌ๋์ด ์์ ์๋ฃํ๋ค๋ ๊ฒ์ ํธ์ถํด์ ์๋ ค์ง๋ ํจ์ (์์ ์ด ๋๋ ํ ํธ์ถ๋๋ ํจ์)
<button>hide</button>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Quibusdam dolorem soluta accusamus sint atque explicabo
nesciunt consequatur beatae quae fuga excepturi corrupti
tempora commodi enim nulla deleniti magni provident?
Vitae.</p>
$(function (){
$("button").click( function (){
// 1. p ์จ๊ธฐ๊ธฐ. (3์ด)
// 2. p ์์ ํ ์จ๊ธฐ์ง ํ์ ๊ฒฝ๊ณ ์ฐฝ ๋์ฐ๊ธฐ๋ฅผ...
/*
$("p").hide(3000);
alert("์์ ํ ์จ๊ฒจ์ต๋๋ค.")
*/
$("p").hide(3000, function (){
// ์ฝ๋ฐฑํจ์
alert("์์ ํ ์จ๊ฒจ์ต๋๋ค.")
});
});
});
* hide(3000, ์ฌ๊ธฐ ์ค๋๊ฒ ์ฝ๋ฐฑํจ์)
jquery selector
1. * ๋ชจ๋ ์์๋ค ex02_02.html
2. #id
3. .class
4. .class, .class
5. element
6. :first ex02_03.html
:last
7. :even ์ง์ 0,2,4 ex02_04.html
:odd ํ์ 1,3,5..
8. :first-child ex02_05.html
:last-child
// ๋ชจ๋ p ํ๊ทธ : ๋ฐฐ๊ฒฝ์ = ๋
ธ๋
// $("p").css("background-color", "yellow");
// ์ฒซ ๋ฒ์งธ p ํ๊ทธ์ ๋ฐฐ๊ฒฝ์ = ๋
ธ๋
// jquery selectors
// first() : jquery method
// last() : jquery method
// eq(index) : jquery method
// $("p").first().css("background-color", "yellow");
$("p:first").css("background-color", "red");
$("p:last").css("background-color", "blue");
* ํจ์, ํ๊ทธ ์ฐจ์ด
:first-of-type
:last - of-type
$(function (){
$("#btn1").click( function (){
// $("p").css("background-color","yellow");
// :first ์ ํ์ : ๋ชจ๋ p ํ๊ทธ ์ค์ ์ฒซ ๋ฒ์งธ p ํ๊ทธ...
$("p:first").css("background-color","red");
}); // btn1_click
$("#btn2").click( function (){
// ์ด๋ค ์์์ ์์(child)์์ ์ค์ ์ฒซ ๋ฒ์งธ ์์์ด p ์ธ ์ ํ์.
$("p:first-child").css("background-color","green");
}); // btn2_click
$("#btn3").click( function (){
// ์ด๋ค ์์์ ์ฒ์ ์ธ p ํ๊ทธ
$("p:first-of-type").css("background-color","blue");
}); // btn3_click
}); // ready
* first-child : ์์์์ ์ค ์ฒซ๋ฒ์งธ๊ฐ p ๋ฉด ํด๋น
* first-of-type : ์์์์ ์ค ์ฒ์์ผ๋ก ์ค๋ p๊ฐ ํด๋น
9. :nth-child(n) ex02_06.html
:nth-last-child(n)
jquery method nth-of-type()
:nth-of-type(n)
:nth-last-of-type(n)
10. :only-child ex02_07.html
:only-of-type
11. ex02_08.html
parent > child : ์ง๊ณ์์๋ง
parent child : ์ง๊ณ์์ + ํ์
parent + child : div ๋ค์ ํ์ ํ๊ทธ๊ฐ p
parent ~ child : div ๋ค์ ๋ฐ๋ผ์ค๋ p ํ๊ทธ์ธ๋ฐ ๋ฐ๋ก๋ค ์๋๋๋ผ๋ ์๊ด์์ (๋ชจ๋ ํ์ ํ๊ทธ์ธ p)
12.
eq(์์, ์์ index)
:eq(index) == ex02_09.html
:gt(no) >
:lt(no) <
13. :not(selector) ex02_10.html
not() jquery method
14. :header ex02_11.html
15. :animated ex02_12.html
์ ๋๋ฉ์ด์ ์งํ์ค์ธ ๋ชจ๋ ์์
16. :focus ex02_13.html
:text <input type="text">
17. :has(selector) ex02_14.html
๊ฐ์ง๋ค.
18. :contains( text string ) ex02_14.html
ํฌํจํ๋ค.
19. :empty ex02_15.html
20. :parent ๋ถ๋ชจ( ์์ )
๋ค๋ฅธ ์์์ ๋ถ๋ชจ๊ฐ ๋๋ ๋ชจ๋ ์์
21. :hidden ex02_16.html
:visible
22. :root
document.documentElement
๋ฃจํธ ์๋ฆฌ๋จผํธ
html ์์
23. :lang( language )
lang ์์ฑ..
css selector < jquery selector
24. ex02_17.html
[attribute]
[attribute=value]
[attribute!=value]
[attribute*=value]
[attribute$=value]
[attribute^=value]
[attribute~=value]
[attribute|=value] X
25.
:disabled
:enabled
:input == <input> ๋ชจ๋ input ํ๊ทธ
:text == input[type=text]
:radio == input[type=radid]
:password == input[type=password]
:chcekbox == input[type=checkbox]
:submit == input[type=submit]
:reset == input[type=reset]
:image == input[type=image]
:file == input[type=file]
:button == input[type=button]
:checked = ์ฒดํฌ๋ input ํ๊ทธ
:selected <option selected=selected>
// $(selector).action()
์ต๊ทผ๋๊ธ