jQuery Selector [attribute$=value] by attribute ending

Introduction

The [attribute$=value] selector selects elements by attribute specific ending string.

$("[attribute$='value']")
Parameter OptionalDescription
attribute Required. the attribute to find
value Required. the string the value should end with

Select all <a> elements with a href attribute that ends with ".org":

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("a[href$='.org']").css("background-color", "yellow");});
</script>/*  w  ww. j  a  v a 2 s. com*/
</head>
<body>

<a href="https://www.java2s.com">java2s.com</a><br>
<a href="http://www.google.com">Google.com</a><br>
<a href="http://www.wikipedia.org">wikipedia.org</a>

</body>
</html>



PreviousNext

Related