select()

jQuery select event occurs when a text is marked or selected in text area or a text field. This event is limited to <input type="text"> fields and <textarea> boxes. When the select event occurs, the select() method attaches a function to run.

Syntax:

snippet
$(selector).select()

It triggers the select event for selected elements.

snippet
$(selector).select(function)

It adds a function to the select event.

Parameters of jQuery select() event

Parameter Description
Function It is an optional parameter. It is used to specify the function to run when the select event is executed.

Example of jQuery select() event

Let's take an example to demonstrate jQuery select() event.

snippet
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>select demo</title>
  <style>
  p {
    color: red;
  }
  div {
    color: blue;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 <p>Select the text on the box: click and drag the mouse to select text.</p>
  <input type="text" value="rookienerd.com">
  <input type="text" value="sssit.org">
  <div></div>
 <script>
$( ":input" ).select(function() {
  $( "div" ).text( "Some text was selected" ).show().fadeOut( 2000 );
});
</script>
 </body>
</html>

Output:

Select the text on the box: click and drag the mouse to select text.

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +