I need, in Blazor, get a reference to a component by its ID. Note: Not using ElementReference, as it is for generic code.
I've used this JS Interop script to do a focus and it works fine for me:
public async Task Focus(string elementId){
await js.InvokeVoidAsync("eval", $@"document.getElementById(""elementId}"").focus()");
}
But what I need from Blazor is get only a reference to the element (the component), that is, the return of: document.getElementById(""{elementId}"")
sending it elementId as a parameter.
Is it possible?
Edit: I've tried with this script but always returns null when calling it from Blazor:
<script>
window.GetElementById = (myId) => {
return document.getElementById(myId);
}
</script>