Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to find inputs with an attribute name starting with specific letter or text using jQuery?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will learn to find input with an attribute name starting with a specific letter or text. This task is implemented using attributeStartWith selector. 

attributeStartWith selector: This selector selects elements that have the specified attribute with a value beginning exactly with a given string. It has two arguments i.e attribute and value.

Syntax:

jQuery( "[attribute^='value']" )
  • attribute: Name of the attribute.
  • value: The value of an attribute (identifier or quoted string).

The attributeStartWith selector can be useful for identifying elements in pages produced by server-side frameworks that produce HTML with systematic element ids.

Example: Finds all inputs with an attribute name that starts with ‘GFG’ and puts the text in them.

HTML




<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <script src=
  </script>
</head>
<body>
  <h2 style="color:green">GeeksforGeeks</h2>
  <input name="GFGletter">
  <input name="input2">
  <input name="GFGtext">
  
<script>
$( "input[name^='GFG']" ).val( "content here!" );
</script>
  
</body>
</html>

Output: 

           

attribute value

My Personal Notes arrow_drop_up
Last Updated : 02 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials