jQuery select()
trigger select event
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>// w w w. j a v a 2 s.c o m <script> $(document).ready(function(){ $("input").select(function(){ $("input").after(" Text marked!"); }); $("button").click(function(){ $("input").select(); }); }); </script> </head> <body> <input type="text" value="Hello World"> <p>Select some text inside the input field.</p> <button>Trigger the select event</button> </body> </html>