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"  />

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

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".


Attribute ends with

 Views: 1544 | Post Order: 19

Write for us