Attribute Ends With Selector [name$=”value’]

It selects all the elements that ends with a given string. It represents element with attribute name whose value is ends with given value.

Description: Selects elements that have the specified attribute with a value ending exactly with a given string.

The comparison is case sensitive.

jQuery(“[attribute$=’value’]”)

attribute: An attribute name.

value: An attribute value Can be either a valid identifier or a quoted string.

Example:

Finds all inputs with an attribute name that ends with ‘letter’ and puts text in them.

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charse"utf-8">
   <title>attributeEndsWith demo</title>
   <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>

<input name="newsletter">
<input name= "milkman">
<input name="job letter">

<script>
$( "input[name$='letter']").val("a letter");
</script>

</body>
</html>
     

Demo:

Leave a Reply

Your email address will not be published. Required fields are marked *