.trigger('click'); 요게 핵심
<button type="button" id="A" onclick="$('#B').trigger('click');" >A버튼</button>
<button type="button" id="B">B버튼</button>
<button type="button" id="C">C버튼</button>
<div class="test_box" style="width:100px;height:100px;background-color:#fa0"></div>
<script>
$('#B').click(function(){
$('.test_box').css({backgroundColor:'#0af'}); //B버튼 누르면 박스가 파란색으로
});
$('#C').click(function(){
$('.test_box').css({backgroundColor:'#ccc'}); //C버튼 누르면 박스가 회색으로
});
</script>
반응형
'웹퍼블리싱 > jquery' 카테고리의 다른 글
[제이쿼리] hasclass / 클릭했을때 if 특정 영역이 아니면 이벤트 발생 시키기 (0) | 2018.11.07 |
---|---|
[JS] 버튼 백그라운드 색깔로 깜빡이게 하기 (2) | 2018.09.21 |
[jquery]특정 태그로 스크롤 이동하기 (0) | 2018.08.22 |
[jquery] 클릭한 요소 제외하고 이벤트 걸기 not() (1) | 2018.08.22 |
[jquery]버튼누르면 지정 div로 스크롤 이동 (0) | 2018.08.20 |
댓글