How To Pass Id Value Onclick Function From Anchor Tag By Click On Image Using Mvc?
Based on the database value status will be Y or N. If it Y means it will active.png will be displayed. it is working fine. when i click active.png image then anchor tag onclick='Ge
Solution 1:
<a id="123" onclick="someFunction(this.id)"></a>
javascript code:-
someFunction(id){ console.log(id) }
Solution 2:
Why are you using in-line JavaScript? You could easily use event delegate on to bind click events.
Here is your modified code:
Status = '<ahref="JavaScript:void(0)"data-id="@item.ModuleID"data-status="@item.Status"class="user-status"title="Disable status"><imgsrc="/img/Active.png"height="22"width="42"/></a>'
Added a class user-status to a tag and assigned id to data-id attribute.
Now get id from click event:
$(document).on('click','.user-status', function(){
var getId = $(this).data('id');
var getStatus = $(this).data('status');
alert("Status Clicked:" + getId );
});
Post a Comment for "How To Pass Id Value Onclick Function From Anchor Tag By Click On Image Using Mvc?"