I have an input text box with some text in it , onclick event I want to run a javascript function to select (highlight) all text that is in this box , how I can do that with jquery?
$(document) wraps a jQuery instance around the document object. ( $ is just an alias for jQuery .)
The HTMLInputElement. select() method selects all the text in a <textarea> element or in an <input> element that includes a text field.
HTML | DOM Input Text select() Method The DOM Input select() method selects all the text content of a textarea or an input element which contains the text field. Syntax: element. select();
You may take a look at this article:
Let's assume that we have the following text input:
<input type="text" id="txtInput" />
In most cases, we would want to have this feature available to all textboxes across our website, so we would create a function to handle this, and call it as needed. Calling this function with the expected argument will make execute the highlighting of the text.
function selectAllText(textbox) { textbox.focus(); textbox.select(); }
Assuming you are developing against DotNetNuke 5, or have jQuery already imported into your website, add the following jQuery to your site for each textbox. (If you have a lot of textboxes, we could do this differently, but that's for a different post.)
jQuery('#txtInput').click(function() { selectAllText(jQuery(this)) });
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