메인메뉴 바로가기

HOME으로 가기


제이쿼리 .hasClass('on'); .removeClass('on'); .addClass('on');

페이지 정보

profile_image
작성자 너갱이
댓글 0건 조회 9,970회 작성일 15-01-29 11:09

본문

 

---------- CSS ----------------

 

<style>

ul { list-style:none; }

button { width:100px; height:50px; }

button.on { border: 5px solid red; }

</style> 

 

 

 

 

-------------- HTML ---------------

 

<ul id="sample">
 <li><button class="on">1</button></li>
 <li><button>2</button></li>
 <li><button>3</button></li>
 <li><button>4</button></li>
</ul>

 

 

 

 

------------------ JS ----------------

 

$("#sample>li>button").click(function(e){
e.stopPropagation(); 

if( !$(this).hasClass("on") ){
$("#sample>li>button.on").removeClass("on");
$(this).addClass("on");
}
});

 

댓글목록

등록된 댓글이 없습니다.