jQuery – Attribute Ends With Selector [name$="value"]

The jQuery selector selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

Source Code

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<div attr="en">Div 1 (not selected)</div>
<div attr="en-US">Div 2 (not selected)</div>
<div attr="english">Div 3 (select this)</div>
<button>Click Here</button>

jQuery("button").click(function () {
	jQuery('div[attr$="sh"]').css("border","2px solid #1E8CBE");


Following example finds all DIV with an attribute ‘attr’ that ends with ‘sh’ and create a border around them.

Div 1 (not selected)
Div 2 (not selected)
Div 3 (select this)


No comments yet.

Leave a Reply