이미지 온, 오프하기
제이쿼리를 사용하여 이벤트시 이미지의 경로를 바꾸는 방법
- img의 attr(src)를 replace한다.
코드
$(function() { var obj = $('.tab img'); $('.tab img').on('click', function(){ $('.tab img').each(function(){ $(this).attr('src', $(this).attr('src').replace('_on.gif', '_off.gif')); }); $(this).attr('src', $(this).attr('src').replace('_off.gif', '_on.gif')); }); });
반응형