[JQuery] ์„ ํƒ์ž

XIXIยท2022๋…„ 6์›” 21์ผ
0

๋Œ€๊ตฌAI์Šค์ฟจ

๋ชฉ๋ก ๋ณด๊ธฐ
39/57
post-thumbnail

๐ŸŒฑ JQuery

โœ๏ธ์ดํด๋ฆฝ์Šค ์ž๋™์™„์„ฑ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•˜๊ธฐ


โœ๏ธํ•จ์ˆ˜

  • JQuery ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ํ•จ์ˆ˜
  • $(๊ฐ์ฒด)๋กœ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ์Œ

โœ๏ธReady ํ•จ์ˆ˜

  • JavaScript์˜ window.onload์™€ ํก์‚ฌ
  • window.onload ํƒœ๊ทธ ๊ฐ์ฒด๊ฐ€ ๋ชจ๋‘ ์ƒ์„ฑ๋˜๋ฉด ๋ฐœ์ƒ๋˜๋Š” ์ด๋ฒคํŠธ

โœ๏ธ์˜ˆ์ œ

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(document).ready(function(){
		$("#result").append("ready <br/>");
	});
</script>
</head>
<body>
	<div id="result"></div>
</body>


โœ๏ธ์„ ํƒ์ž

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		/*
		$("*").css("background-color", "yellow");
		$("p").css("background-color", "blue");
		$("div").css("background-color", "green");
		*/
		
		$("#test1").css("color", "yellow");
		$("#test2").css("color", "blue");
		$(".test3").css("color", "green");
	});
</script>
</head>
<body>
	<p id = "test1"> ๋ฌธ์ž์—ด1 </p>
	<p class = "test3"> ๋ฌธ์ž์—ด2 </p>
	<div id = "test2"> ๋ฌธ์ž์—ด3 </div>
	<div class = test3> ๋ฌธ์ž์—ด4 </div>
</body>

โœ๏ธ์„ ํƒ์ž2

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("div").css("background-color", "yellow");
		$("p").css("background-color", "yellow");
		
		// $("div, p").css("background-color", "yellow");
		
		$("#a1").css("color", "red");
		$("#a2").css("color", "red");
		
		// $("#a1, #a2").css("color", "red");
	});
</script>
</head>
<body>
	<div id = "a1"> div 1</div>
	<div>div 2</div>
	<p id = "a2">p 1</p>
	<p>p 2</p>
</body>

<script>
	$(function(){
		// $("div").css("background-color", "yellow");
		// $("p").css("background-color", "yellow");
		
		$("div, p").css("background-color", "yellow");
		
		// $("#a1").css("color", "red");
		// $("#a2").css("color", "red");
		
		$("#a1, #a2").css("color", "red");
	});
</script>

๋‚ด์šฉ์ด ๊ฐ™์„ ๊ฒฝ์šฐ ์„ ํƒ์ž๋ฅผ , ๋กœ ๋™์‹œ์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค

โœ๏ธ์„ ํƒ์ž3

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function() {
		$("#a1 > h1").css("background-color", "yellow")
	});
</script>
</head>
<body>
	<div id = "a1">
		<h1>์ž์‹ ํƒœ๊ทธ h1</h1>
		<div>
			<h1>์ž์† ํƒœ๊ทธ h1</h1>
		</div>
	</div>
</body>

  • ์„ ํƒ์ž1 > ์„ ํƒ์ž2 : ํƒœ๊ทธ ๋ฐ”๋กœ ํ•˜์œ„(์„ ํƒ์ž1์˜ ์ž์‹์„ ํƒ์ž)๋งŒ ์ ์šฉ
<script>
	$(function() {
		$("#a1 > h1").css("background-color", "yellow")
		$("#a1 h1").css("background-color", "yellow")
	});
</script>

  • ์„ ํƒ์ž1 ์„ ํƒ์ž2 : ํƒœ๊ทธ ์•„๋ž˜ ๋ชจ๋“  ์„ ํƒ์ž2 ์ ์šฉ

โœ๏ธ์„ ํƒ์ž4

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function() {
		$("div.a1").css("background-color", "yellow");
		$("div.a2").css("background-color", "red");
		$("p.a1").css("background-color", "purple");
		$("p.a2").css("background-color", "blue");
	});
</script>
</head>
<body>
	<div class = "a1">div a1</div>
	<div class = "a2">div a2</div>
	<p class = "a1">p a1</p>
	<p class = "a2">p a2</p>
</body>

์„ ํƒ์ž1.์„ ํƒ์ž2 : ์„ ํƒ์ž1์ด๋ฉด์„œ ์„ ํƒ์ž2๋ฅผ ๊ฐ€์ง€๋Š” ๊ฒƒ์— ์ ์šฉ. ๋‘˜ ๋‹ค ๋งŒ์กฑํ•ด์•ผํ•จ and ๊ฐœ๋…

โœ๏ธ์„ ํƒ์ž5

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function() {
		$("#a1 + p").css("background-color","yellow");
	});
</script>
</head>
<body>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p id = "a1">p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
</body>

์„ ํƒ์ž1 + ์„ ํƒ์ž2 : ์„ ํƒ์ž1 ํƒœ๊ทธ ๋ฐ”๋กœ ๋‹ค์Œ์— ์žˆ๋Š” ์„ ํƒ์ž2 ํƒœ๊ทธ๋ฅผ ์„ ํƒํ•จ.
๊ทธ๋ž˜์„œ 4๋ฒˆ์งธ id์ธ a1 ๋ฐ”๋กœ ๋‹ค์Œ p ํƒœ๊ทธ์— css๊ฐ€ ์ ์šฉ๋œ ๊ฒƒ์„ ํ™•์ธ

โœ๏ธ์„ ํƒ์ž6

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function() {
		// $("#a1 + p").css("background-color","yellow");
		$("#a1 ~ p").css("background-color","yellow");
	});
</script>
</head>
<body>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p id = "a1">p ํƒœ๊ทธ a1</p>
	<div>div ํƒœ๊ทธ</div>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
</body>

์„ ํƒ์ž1 ~ ์„ ํƒ์ž2 : ์„ ํƒ์ž1 ๋’ค๋กœ ์žˆ๋Š” ์„ ํƒ์ž2 ํƒœ๊ทธ๋“ค ๋ชจ๋‘ ์„ ํƒ

๐ŸŒฑ JQuery ์ˆœ์„œ ์„ ํƒ์ž

โœ๏ธ์ˆœ์„œ ์„ ํƒ์ž1

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:first").css("background-color","yellow");
		$("p:first-child").css("color","orange");
		$("p:first-of-type").css("font-size","30px");
	});
</script>
</head>
<body>
	<p> ํƒœ๊ทธ </p>
	<hr/>
	<div>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
	</div>
	<hr/>
	<div>
		<div>div ์•ˆ์— div ํƒœ๊ทธ</div>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
	</div>
</body>

  • first : ์„ ํƒ์ž ํƒœ๊ทธ ์ค‘ ๊ฐ€์žฅ ์ฒ˜์Œ
  • first-child : ์„ ํƒ์ž ํ•ด๋‹น ํƒœ๊ทธ ์ค‘ ๊ฐ ์˜์—ญ๋ณ„ ์ฒซ ๋ฒˆ์งธ ํƒœ๊ทธ, ์ฒซ ํƒœ๊ทธ๊ฐ€ ์„ ํƒ์ž์— ํ•ด๋‹นํ•˜์ง€ ์•Š์œผ๋ฉด ์„ ํƒ์•ˆ๋Œ
  • first-of-type : ์„ ํƒ์ž ํƒœ๊ทธ ์œ ํ˜• ์˜์—ญ๋ณ„ ๊ฐ€์žฅ ์ฒซ ๋ฒˆ์งธ ํƒœ๊ทธ

โœ๏ธ์ˆœ์„œ ์„ ํƒ์ž2

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:last").css("background-color","yellow");
		$("p:last-child").css("color","orange");
		$("p:last-of-type").css("font-size","30px");
	});
</script>
</head>
<body>
	<p> ํƒœ๊ทธ </p>
	<hr/>
	<div>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
	</div>
	<hr/>
	<div>
		<div>div ์•ˆ์— div ํƒœ๊ทธ</div>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
		<p> div ์•ˆ์— p ํƒœ๊ทธ </p>
	</div>
</body>

  • last : ์„ ํƒ์ž ํƒœ๊ทธ ์ค‘ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰
  • last-child" : ์„ ํƒ์ž ํ•ด๋‹น ํƒœ๊ทธ ์ค‘ ๊ฐ ์˜์—ญ๋ณ„ ๋งˆ์ง€๋ง‰ ํƒœ๊ทธ, ๋งˆ์ง€๋ง‰ ํƒœ๊ทธ๊ฐ€ ์„ ํƒ์ž์— ํ•ด๋‹นํ•˜์ง€ ์•Š์œผ๋ฉด ์„ ํƒ ์•ˆ๋Œ
  • last-of-type : ์„ ํƒ์ž ํƒœ๊ทธ ์œ ํ˜• ์˜์—ญ๋ณ„ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ํƒœ๊ทธ

๐ŸŒฑ JQuery ๊ทธ ์™ธ ์ˆœ์„œ ํ•„ํ„ฐ ์„ ํƒ์ž

โœ๏ธodd, even

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:odd").css("background-color","yellow");
		$("p:even").css("background-color","red");
	});
</script>
</head>
<body>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
	<p>p ํƒœ๊ทธ</p>
</body>

odd : ํ™€์ˆ˜
even : ์ง์ˆ˜

โœ๏ธonly

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:only-child").css("background-color","yellow");
		$("p:only-of-type").css("color","orange");
	});
</script>
</head>
<body>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<div>div ํƒœ๊ทธ</div>
	</div>
</body>

only-child : ์ž์‹ ํƒœ๊ทธ๊ฐ€ ํ•˜๋‚˜๋งŒ ์žˆ๋Š” ๊ฒฝ์šฐ
only-of-type : pํƒœ๊ทธ ์œ ํ˜•์ด ํ•˜๋‚˜๋งŒ ์žˆ์œผ๋ฉด ์ ์šฉ

๐ŸŒฑ ์ธ๋ฑ์Šค ๋ฒˆ์งธ ํƒœ๊ทธ ์„ ํƒ

โœ๏ธ์ธ๋ฑ์Šค1

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:eq(3)").css("background-color","yellow");
		$("p:nth-child(1)").css("color","orange");
		$("p:nth-of-type(1)").css("font-style","italic");
	});
</script>
</head>
<body>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<div>div ํƒœ๊ทธ</div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
</body>

  • eq(์ธ๋ฑ์Šค) : ์„ ํƒ์ž ํƒœ๊ทธ ์ธ๋ฑ์Šค ํ•ด๋‹น ๋ฒˆํ˜ธ์— ์ ์šฉ
  • nth-child(์ธ๋ฑ์Šค) : ์„ ํƒ์ž ์ž์‹ ํƒœ๊ทธ ์ธ๋ฑ์Šค ํ•ด๋‹น ๋ฒˆํ˜ธ์— ์ ์šฉ, ๋‹จ ํ•ด๋‹น ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” ์ž์‹ ํƒœ๊ทธ๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ์ ์šฉ ์•ˆํ•จ.
  • nth-of-type(์ธ๋ฑ์Šค) : ์„ ํƒ์ž ์ž์‹ ํƒœ๊ทธ ์œ ํ˜• ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ์— ์ ์šฉ

โœ๏ธ์ธ๋ฑ์Šค2

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:gt(0)").css("background-color","yellow");
		$("p:lt(7)").css("color","blue");
		$("p:nth-last-child(1)").css("font-size","30px");
		$("p:nth-last-of-type(1)").css("font-style","italic");
	});
</script>
</head>
<body>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
	<hr/>
	<div>
		<div>div ํƒœ๊ทธ</div>
		<p>p ํƒœ๊ทธ</p>
		<p>p ํƒœ๊ทธ</p>
	</div>
</body>

  • gt(์ธ๋ฑ์Šค) : ์„ ํƒ์ž์— ํ•ด๋‹นํ•˜๋Š” ํƒœ๊ทธ ์ค‘ ์ธ๋ฑ์Šค(0๋ถ€ํ„ฐ ์‹œ์ž‘)๋ฒˆ
    ์งธ ํƒœ๊ทธ ์ดํ›„์˜ ํƒœ๊ทธ๋“ค์ด ์„ ํƒ
  • lt(์ธ๋ฑ์Šค) : ์„ ํƒ์ž์— ํ•ด๋‹นํ•˜๋Š” ํƒœ๊ทธ ์ค‘ ์ธ๋ฑ์Šค(0๋ถ€ํ„ฐ ์‹œ์ž‘)๋ฒˆ
    ์งธ ํƒœ๊ทธ ์ด์ „์˜ ํƒœ๊ทธ๋“ค์ด ์„ ํƒ
  • nth-last-child(์ธ๋ฑ์Šค) : ๋’ค์—์„œ ์ธ๋ฑ์Šค(1๋ถ€ํ„ฐ ์‹œ์ž‘)๋ฒˆ์งธ ํƒœ๊ทธ๊ฐ€
    ์„ ํƒ. ์ธ๋ฑ์Šค ๋ฒˆ์งธ ํƒœ๊ทธ๊ฐ€ ์„ ํƒ์ž์™€ ๋‹ค๋ฅด๋ฉด ์„ ํƒ๋˜์ง€ ์•Š์Œ
  • nth-last-of-type(์ธ๋ฑ์Šค) : ๋’ค์—์„œ ์ธ๋ฑ์Šค(1๋ถ€ํ„ฐ ์‹œ์ž‘)๋ฒˆ์งธ ํƒœ๊ทธ
    ๊ฐ€ ์„ ํƒ

โœ๏ธnot

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p:not(.a1)").css("background-color","yellow");
		
	});
</script>
</head>
<body>
	<p>p ํƒœ๊ทธ</p>
	<p class = "a1">p ํƒœ๊ทธ a1 class</p>
	<p class = "a2">p ํƒœ๊ทธ a2 class</p>
	
</body>

not ์•„๋‹Œ ๊ฒƒ์„ ์„ ํƒํ•จ

๐ŸŒฑ ์†์„ฑ ์„ ํƒ์ž

โœ๏ธ์†์„ฑ ์„ ํƒ์ž1

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p[title]").css("background-color", "yellow");
		$("p[title = 'aaa1']").css("background-color", "orange");
		$("p[title != 'aaa1']").css("color", "red");
	});
</script>
</head>
<body>
	<p>์†์„ฑ์ด ์—†๋Š” p ํƒœ๊ทธ</p>
	<p title = "aaa1">title์ด aaa1์ธ p ํƒœ๊ทธ</p>
	<p title = "aaa2">title์ด aaa2์ธ p ํƒœ๊ทธ</p>
</body>

  • [์†์„ฑ] : ์†์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • [์†์„ฑ = ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • [์†์„ฑ != ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ํƒœ๊ทธ๋ฅผ
    ์„ ํƒ

โœ๏ธ์†์„ฑ ์„ ํƒ์ž2

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		/* $("p[title]").css("background-color", "yellow");
		$("p[title = 'aaa1']").css("background-color", "orange");
		$("p[title != 'aaa1']").css("color", "red"); */
		
		$("p[title $= 'a3']").css("background-color", "blue");
		$("p[title |= 'aaa3']").css("color", "green");
		$("p[title ^= 'aaa3']").css("font-size", "30px");
	});
</script>
</head>
<body>
	<!-- <p>์†์„ฑ์ด ์—†๋Š” p ํƒœ๊ทธ</p>
	<p title = "aaa1">title์ด aaa1์ธ p ํƒœ๊ทธ</p>
	<p title = "aaa2">title์ด aaa2์ธ p ํƒœ๊ทธ</p> -->
	
	<p title = "aaa3">title์ด aaa3์ธ p ํƒœ๊ทธ</p>
	<p title = "aaa3-test">title์ด aaa3-test์ธ p ํƒœ๊ทธ</p>
	<p title = "aaa3test">title์ด aaa3test์ธ p ํƒœ๊ทธ</p>
</body>

  • [์†์„ฑ $= ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’์œผ๋กœ ๋๋‚˜๋Š” ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • [์†์„ฑ |= ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ์†์„ฑ์˜ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๊ฑฐ๋‚˜ ์ง€์ •
    ๋œ ์†์„ฑ์œผ๋กœ ์‹œ์ž‘ํ•˜๊ณ  ํ•˜์ดํ”ˆ์œผ๋กœ ์—ฐ๊ฒฐ๋œ ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • [์†์„ฑ ^= ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ํƒœ๊ทธ๋ฅผ ์„ 
    ํƒ

โœ๏ธ์†์„ฑ ์„ ํƒ์ž3

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$("p[title ~= 'aa']").css("color", "purple");
		$("p[title *= 'aa']").css("background-color", "yellow");
	});
</script>
</head>
<body>
	<p title = "aaa4">title์ด aaa4์ธ p ํƒœ๊ทธ</p>
	<p title = "aaa5-test">title์ด aaa5-test์ธ p ํƒœ๊ทธ</p>
	<p title = "aa a6">title์ด aa a6์ธ p ํƒœ๊ทธ</p>
	<p title = "aa">title์ด aa์ธ p ํƒœ๊ทธ</p>
</body>

  • [์†์„ฑ ~= ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’์„ ๋‹จ์–ด๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํƒœ
    ๊ทธ๋ฅผ ์„ ํƒ
  • [์†์„ฑ *= ๊ฐ’] : ์†์„ฑ์˜ ๊ฐ’์ด ์ง€์ •๋œ ๊ฐ’์„ ํฌํ•จํ•˜๋Š” ํƒœ๊ทธ๋ฅผ ์„ ํƒ

๐ŸŒฑ ์ƒํƒœ ์„ ํƒ์ž

โœ๏ธ์ƒํƒœ ์„ ํƒ์ž1

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
	$(function(){
		$(":header").css("color", "red");
		$(":focus").css("backgroud-color", "green");
		$("div:contains('Hello')").css("font-size", "3px");
		$("div:has(p)").css("font-size", "italic");
	});
</script>
</head>
<body>
	<p>p ํƒœ๊ทธ</p>
	<h1>h1 ํƒœ๊ทธ</h1>
	<h3>h3 ํƒœ๊ทธ</h3>
	
	<input type="text" autofocus="autofocus"/><br/>
	<input type="text"/><br/>
	
	<div>Hello World</div>
	<div>Hello World</div>
	<div>Hi World</div>
	
	<div>
		<p>p ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” div ํƒœ๊ทธ</p>
	</div>
	<div>
		<div>div ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” div ํƒœ๊ทธ</div>
	</div>
</body>

  • ํƒœ๊ทธ์˜ ์ƒํƒœ์— ๋”ฐ๋ผ ์„ ํƒํ•˜๋Š” ์„ ํƒ์ž
  • :header : h1 ~ h6 ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • :focus : ํ˜„์žฌ ํฌ์ปค์Šค๊ฐ€ ์ฃผ์–ด์ง„ ํƒœ๊ทธ๋ฅผ ์„ ํƒ
  • :contains(โ€˜๋ฌธ์ž์—ดโ€˜) : ์ง€์ •๋œ ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š” ํƒœ๊ทธ๋ฅผ ์„ 
    ํƒ
  • :has(์„ ํƒ์ž) : ์ง€์ •๋œ ์„ ํƒ์ž๋ฅผ ํฌํ•จํ•˜๊ณ  ํƒœ๊ทธ๋ฅผ ์„ ํƒ

๐Ÿƒ ์–ด๋ ค์› ๋˜ ์  or ํ•ด๊ฒฐ๋ชปํ•œ ๊ฒƒ

์„ ํƒ์ž ์ข…๋ฅ˜์™€ ์–‘์ด ๋งŽ์•˜๋‹ค

๐Ÿ€ ํ•ด๊ฒฐ๋ฐฉ๋ฒ• ์ž‘์„ฑ

โœ๏ธ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐ์„ ํ–ˆ๋Š”๊ฐ€?
โœ๏ธ ์ด๋ ‡๊ฒŒ ์ดํ•ด๋ฅผ ํ–ˆ๋‹ค
โœ๏ธ ์–ด๋””๊นŒ์ง€ ์ดํ•ดํ–ˆ์ง€?
โœ๏ธ ๋‹ค์Œ์— ์‹œ๋„ํ•ด๋ณผ ๋ฐฉ๋ฒ•
์„ ํƒ์ž๋ฅผ ํ™œ์šฉํ•ด์„œ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค

๐ŸŒท ํ•™์Šต ์†Œ๊ฐ

๋‹ค์–‘ํ•œ ์„ ํƒ์ž ํ™œ์šฉ์„ ํ†ตํ•ด ํšจ์œจ์ ์ธ ์ ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋œ ์ˆ˜์—…์ด์—ˆ๋‹ค.

profile
Life is experience:)

0๊ฐœ์˜ ๋Œ“๊ธ€