jQuery > Selectors

element[attribute$='value' - Attribute ends with in jQuery

How to select elements whose attribute value ends with certain characters?


To select particular elements whose attribute value ends with certain characters we can use attribute ends with selector.

    <input id="txtName" type="text" data-id="txt Name" />
    <input id="FirstName" type="text" data-id="name txt" />
    <input id="Address" type="text" data-id="name txt" />
    <input id="btnTest" type="button" value="Button"  />

    <script>
        $(function () {
            $("input[id$='Name']").css("border", "1px solid red");
        });
    </script>

In above case, first all input elements are selcted and then based on id attribute whose value ends with "Name" are selected.

In above code snippet, only first two elements will get selected (and css style of border 1px solid will get applied) as those elements id attribute values ends with "Name".

Output

Attribute ends with

 Views: 8359 | Post Order: 19



Write for us






Hosting Recommendations