Sangil's blog

https://github.com/ChoiSangIl Admin

WEB href의 this와 onClick의 this의 차이 DEV / WEB

2018-11-20 posted by sang12


업무 중에 삽질한 경험을 남깁니다.

<a href="javascirpt:delete(this);">test</a>
<a onClick="delete(this);">test</a>
delete = function(target){
    $(target).remove();
}
위와 같이 자신의 요소를 삭제 할려고 this.remove() 형태로 코딩을 했습니다. 이때  href를 사용하게되면 this가 먹히지 않는다고하네요.

그래서 onClick으로 사용하니..해결. herf와 onClick은 용도가 다르니 그러는 거 같은데.. 정확한 이유는 찾아봐야 겠네요^^

#href this #onClick this #WEB
REPLY