티스토리 뷰
See the Pen [jQuery] .addClass() .removeClass() by mill (@millfeel) on CodePen.
특정 요소에 클래스를 추가하고 제거하는 구문이다.
// 클래스 추가하기
$('선택자').addClass('추가할 클래스명');
// 클래스 제거하기
$('선택자').removeClass('제거할 클래스명');
[JS와 비교하기]
// JS
const $box = document.querySelector('.box');
$box.addEventListener('mouseover', function () {
this.classList.add('box__circle');
});
$box.addEventListener('mouseout', function () {
this.classList.remove('box__circle');
});
// jQuery
$(document).ready(function () {
$('.box').mouseover(function(){
$(this).addClass('box__circle');
}).mouseout(function(){
$(this).removeClass('box__circle');
});
});
[공부좌표]
인터랙티브 웹디자인북 p145
'이론 > jQuery' 카테고리의 다른 글
[jQuery] e.pageX / e.pageY (0) | 2021.10.24 |
---|---|
[jQuery] 문자를 가져오거나 변경하는 .text()와 HTML 태그 구조를 포함해서 가져오거나 변경하는 .html() (0) | 2021.10.24 |
[jQuery] .hide() .show() .fadeOut() .fadeIn() (0) | 2021.10.23 |
[jQuery] .width() .height() (0) | 2021.10.23 |
[jQuery] 반복문 .each() (0) | 2021.10.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- prototype 프로퍼티
- javascript class
- outerHeight
- 동치 연산자
- clientHeight
- __proto__
- constructor
- innerHeight
- 점 표기법
- 객체의 프로퍼티
- offsetHeight
- clinetTop
- scrollHeight
- [[Prototype]]
- offsetTop
- scrollTop
- 부등 연산자
- 링크막기 #a링크막기
- 프로퍼티
- 일치 연산자
- @font-face
- 대괄포 표기법
- 동등 연산자
- 불일치 연산자
- property
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함