๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŒ  ์ž๋ฐ” ์„œ๋ฒ„ ํŽ˜์ด์ง€ JSP/๐Ÿช ์ œ์ด ์ฟผ๋ฆฌ jQuery

3๏ธโƒฃ ์ œ์ด ์ฟผ๋ฆฌ - CSS, MouseOver, ์†์„ฑ ์ถ”๊ฐ€

by Meteora_ 2021. 3. 5.
728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<style type="text/css">
.back{
	color: #ffff00;
}

</style>

</head>
<body>

<table border="1">
<col width="50"><col width="200"><col width="150">

<tr>
	<th>๋ฒˆํ˜ธ</th><th>์ด๋ฆ„</th><th>๋‚˜์ด</th>
</tr>

<tr class="cls">
	<th>1</th><td>ํ™๊ธธ๋™</td><td>24</td>
</tr>

<tr class="cls">
	<th>2</th><td>์„ฑ์ถ˜ํ–ฅ</td><td>16</td>
</tr>

<tr class="cls">
	<th>3</th><td>์ผ์ง€๋งค</td><td>22</td>
</tr>

</table>

<p>p tag</p>

<button type="button">๋ฒ„ํŠผ</button>

<button type="button" id="lovebtn">input</button>

<script type="text/javascript">
$(document).ready(function(){
	$("tr.cls").mouseover(function() {
		$(this).css("background", "#00ff00");
	});
	
	$("tr.cls").mouseout(function() {              //์ผ์ •๋ถ€๋ถ„๋งŒ css๋ฅผ ์ ์šฉ์‹œํ‚ฌ๋• class๋ฅผ ์„ค์ •ํ•˜๊ณ  ํƒœ๊ทธ.ํด๋ž˜์Šค๋ช…์œผ๋กœ ์ ‘๊ทผํ•œ๋‹ค.
		$(this).css("background", "#fff");
	});
	
	$("button").click(function() {
		//setter
		$("p").css("background", "#0000ff");
		$("p").text("์—ฌ๊ธฐ๋Š” p ํƒœ๊ทธ");
		
		//getter
		let color = $("p").css("background"); //property
		let text = $("p").text();
		
		
		//attribute , ์†์„ฑ์„ ์ถ”๊ฐ€ํ• ๋•Œ(id๊ฐ’์„ ์ถ”๊ฐ€)
		$("p").attr("id","pid");
		alert($('p').attr("id")); //id ํ™•์ธ
		
		//css์ถ”๊ฐ€
		/* $("p").attr("class","back"); */
		
		$("p").addClass("back"); //์œ„์™€ ์•„๋ž˜๋Š” ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌ ํด๋ž˜์Šค๋ฅผ ์ ์šฉํ–ˆ์Œ.
		
		// html(), text(), val(), css(), attr(), prop() ์ž์ฃผ์“ฐ์ธ๋‹ค.
	});
	
	$("#btn").click(function(){
		
		$("p").removeClass("back");
	});
});


</script>



</body>
</html>

๋Œ“๊ธ€