I was wondering if there was a way for text inside a input box (pre loaded using value="") to highlight when the user clicks on it?
input type='text' name='url' id='url' value='http://www.a-link.com/' />
EDIT
I need the text to he highlighted so the user can copy it.
To auto-highlight an input field on focus with JavaScript, we can call select on the element when the focus event is emitted. to add an input with a value filled in. to select the input with document.
For selecting the content of an input (with highlight), use: el. select() . For css manual highlight, see @HashemQolami answer.
Description. The HTML <mark> tag is used to mark or highlight text that is of special interest or relevance in an HTML document. Browsers traditionally render the text found within the <mark> tag as text with a yellow background color.
To check if an input field has focus with JavaScript, we can use the document. activeElement property to get the element in focus. to add an input. to check if the input element is focused.
<input type="text" name="textbox" value="Test" onclick="this.select()" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With