728x90
이번 글에서는 클래스에 관련된 함수들을 모아보도록 하자.
1. addClass() : 해당 제이쿼리 객체에 클래스를 추가한다.
.this { font-size : 20px; } $(document).ready(function() { $("#this").addClass("this"); });디스 이즈 스파르타!!
2. removeClass() : 해당 제이쿼리 객체의 클래스를 삭제한다.
.this { font-size : 20px; } $(document).ready(function() { $("#this").removeClass("this"); });디스 이즈 스파르타!!
3. toggleClass() : 해당 제이쿼리 객체에 클래스가 있다면 삭제하고 없다면 추가한다.
.this { font-size : 20px; } $(document).ready(function() { $("#this").click(function() { $("#this").toggleClass("this"); }); });디스 이즈 스파르타!!
4. hasClass() : 클래스가 있다면 true, 없으면 false 를 리턴한다.
.this { font-size : 20px; } $(document).ready(function() { $("#this").click(function() { $("#this").toggleClass("this"); if($("#this").hasClass("this")) { alert("클래스가 생성 했습니다!"); } else { alert("클래스를 삭제 했습니다!"); } }); });디스 이즈 스파르타!!
728x90
'개발 > jQuery' 카테고리의 다른 글
jQuery (제이쿼리) - jQuery map() (2) | 2018.06.17 |
---|---|
jQuery (제이쿼리) - jQuery filter(), not() (0) | 2018.06.17 |
jQuery (제이쿼리) - jQuery 특정 단어를 기준으로 나누고 붙이는 split, join (0) | 2018.06.17 |
jQuery (제이쿼리) - jQuery 비교연산자 셀렉터 eq, lt, gt, not (2) | 2018.06.10 |
댓글