본문 바로가기
JQuery

add

by NamGH 2023. 9. 21.

add는 선택한 요소들을 확장시킬때 사용한다 

예제
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	div{
		width: 50px;
		height: 50px;
		margin: 10px;
		float: left;
	}
	p{
		clear: left;
	}
	.redBorder{
		border: 2px solid red;
	}
	.yellow{
		background: yellow;
	}
</style>
<script src = "../js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('button').click(function(){
			$('div').addClass('redBorder').add('p').addClass('yellow');
		
			/* $('div').addClass('redBorder');
			$('div').addClass('yellow');
			$('p').addClass('yellow'); */
		})
	})
</script>
</head>
<body>
	<div></div>
	<div></div>
	<div></div>
	<p>이곳은 p영역</p>
	<button>클릭</button>
</body>
</html>
결과

버튼을 클릭시 다음과 같은 결과가 나온다

 

 

'JQuery' 카테고리의 다른 글

[jQuery] children  (0) 2023.09.21
filter  (0) 2023.09.21
toggle  (0) 2023.09.21
attr  (0) 2023.09.20
nth  (0) 2023.09.20