jQuery Selectors: Matches the end of the attribute value E[attr$=value]


Matches any element E whose attribute attr ends in value.

In other words, the value matches the end of the attribute value.

In the example below, we use preventdefault function to prevent the default event, which is to follow the link, to happen.

<!DOCTYPE html>
<head lang='en'>
    <meta charset='UTF-8'>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
        $(function () {
            $("a[href$='.com']").click(function (event) {

<a href='http://google.com'>This is to google</a>
<a href='http://yahoo.com'>This is to yahoo</a>

If we have an element with a class name topMenu, we can also match it with class$=Menu.

Series Navigation<< jQuery Selectors: Select elements that have attribute $(‘[attr]‘)
jQuery Selectors: Content filter selector-contains >>