When a user clicks a specific button, I need an input field to be focused with its text value selected entirely to allow users to replace the entire value while typing.
This is the markup for the input field:
<input type="text" id="descriptionField" class="form-control">
And here's the function that handles the focus/select functionality:
public copy(): void {
document.getElementById("descriptionField").focus();
document.getElementById("descriptionField").select();
}
While .focus()
works fine, .select()
throws an error:
TS2339: Property 'select' does not exist on type 'HTMLElement'.
I've searched for solutions without relying on jQuery. Is there a way to solve this using native implementation or TypeScript?