Skip to content

Blazor onmousedown get event target #43519

@Jimmys20

Description

@Jimmys20

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Is there a way to obtain the event target element when handling an event from razor? I want to get a reference to the object onto which the event was dispatched. Let's say I have a razor component with the following code:

<div id="container" @onmousedown="HandleMouseDown">
    <div id="nested">...</div>
    <button>Submit</button>
</div>

@code {
    private void HandleMouseDown(MouseEventArgs args)
    {
        // no way check which child element is the event target.
    }
}

In javascript I can do the following.

var container = document.getElementById("container");

container.onmousedown = function(e) {
    console.log(e.target);
};

Describe the solution you'd like

Add Target property to the MouseEventArgs which will return an ElementReference of the element onto which the event was dispatched.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions