본문 바로가기
jQuery

jQuery removeClass, addClass - 활용하기

by 호랭형님 2020. 1. 18.

 

 


 

이벤트 실행 전

 

 


 

 

이벤트 실행 후

 

 

 


 

 

$('img').hover(function(){

   $(this).addClass('csty'); --> 현재 이벤트 중인 img에 style 주기

}, function(){

   $(this).removeCalss('csty'); --> 현재 이벤트 중인 img에 style 제거하기

})

 

 

$('.guess_box').on('click', function(){

   $('p').remove(); --> p태그 지우기

   $('<p>', {'id' : 'sale'}).appendTo(this); --> id sale인 p태그 생성

   ran = (Math.floor)(Math.random()*6+5); --> 랜덤값 생성

   $('p').text("할인율 : " + ran + "%"); --> p태그에 랜덤값 입력하기

 

   $(this).unbind('click'); --> 객체의 이벤트 종료

})

댓글