jQuery

08. [jQuery] a 태그 이벤트 제거하는 방법

drizzle0925 2021. 11. 26. 13:28
728x90

a태그의 이벤트를 제거하는 방법은 2가지 있습니다.

 

방법 1

href 속성 값에 javascript:void(0) 값을 넣어줍니다.

<a href="javascript:void(0)">클릭해도 반응 없음</a>

 

방법 2

click 이벤트 안에 e.preventDefault(); 를 넣어줍니다.

<a href="https://google.com" id="link">google.com</a>

<script>
$("#link").on("click",function(e){
    e.preventDefault();
});
</script>

위 코드를 입력하면 google.com으로 이동하지 않습니다. 

728x90