본문 바로가기
javaScript/jQuery

jQuery 제이쿼리 addClass사용해서 간단하게 클래스 적용하기

by mooyou 2021. 5. 18.
728x90
300x250

 

jQuery addClass를 사용해서 간단하게 크래스를 적용하는 방법입니다.

 

$(적용할 엘리먼트).addClass(클래스명);

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>addClass로 css변경하기</title>
<style type="text/css">
	span { font-size: 30pt   }
	.redtext   { color : #f00   }
</style>
<script src="../js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
	$('span').addClass('redtext');
</script>	
</head>
<body>
<span> simple </span>
<script type="text/javascript">
	$('span').addClass('redtext');
</script>
</body>
</html>

 

 

실행 결과 확인하기

See the Pen ZEepZBG by kim oya (@ttuttu) on CodePen.

728x90
반응형

댓글