Toggle the class 'highlight' when a paragraph is clicked.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>toggleClass demo</title>
<style>
p {
margin: 4px;
font-size: 16px;
font-weight: bolder;
cursor: pointer;
}
.blue {
color: blue;
}
.highlight {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<p class="blue">Click to toggle</p>
<p class="blue highlight">highlight</p>
<p class="blue">on these</p>
<p class="blue">paragraphs</p>
<script>
$( "p" ).click(function() {
$( this ).toggleClass( "highlight" );
});
</script>
</body>
자바스크립트 억음부호 (backtik) 사용법 (0) | 2022.10.12 |
---|---|
event.target.id 관련 (0) | 2022.09.20 |
Jquery Form Serialize Disabled 컨트롤 넘기는 방법 (0) | 2021.03.24 |
[JQuery] input 객체 - readonly, disabled 처리 (0) | 2021.03.24 |
jQuery.merge(first, second) Returns:Array (0) | 2021.02.09 |
댓글 영역