The Input Search select() Method in HTML DOM is used to select the content of the Input search text field. It is the predefined method of the Search object.
Syntax:
searchObject.select()
- Parameters: It does not accept any parameter.
- Return Value: It does not return any value.
Example: This example uses the Input Search select() method to select the content inside the search field.
HTML
<!DOCTYPE html> < html >
< head >
< style >
h1 {
color: green;
}
body {
text-align: center;
}
</ style >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >Input Search select() Method</ h2 >
< input type = "Search" id = "test"
placeholder = "Type to search.."
value = "GeeksForGeeks" >
< br >
< br >
< br >
< button onclick = "selectContent()" >
Select the Content of Search Field
</ button >
< script >
function selectContent() {
// Use the select() method
document.getElementById(
"test"
).select();
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome 5 and above
- Edge 12 and above
- Firefox 4 and above
- Safari 5 and above
- Opera 10.6 and above