javascript - Get id of element which raised event -
i working in asp.net mvc. have following js
<script> function fun() { alert($(this).attr("id")); } </script> and following code in view
@ { int i=1; } @for(i=1;i<10;i++) { <a href="" id="@i" onclick="fun()">abc</a> } i want id of anchor calls fun(), undefined value always. please help.
pass this
<a href="" id="@i" onclick="fun(this)">abc</a> function fun(elem) { alert(elem.id); } in case refering , this refer window object . if pass element function , elemnent available in scope of function acts closure.
Comments
Post a Comment