Im trying to click an element and get the offsetTop position. Im trying to do this with this javascript code:
window.ShowAlert = function myFunction(event) {
console.log("Hello World.");
alert(event.target.offsetTop);
}
This code is inside a folder in my wwwroot and in my Index.razor I have this code:
@inject IJSRuntime jsRuntime
<div>
<Member OnClick="MemberFunction" />
</div>
@code {
void MemberFunction()
{
jsRuntime.InvokeAsync<object>("ShowAlert");
}
}
When I run this the console log appears as expected but the alert doesn't, and I tried to change the alert to appear "Hello World" and works fine, the problem is the event.target.
Why the alert with the offsetTop position is not working?
Thank you for your attention.