jQuery > Selectors

element[attribute^='value' - Attribute starts with in jQuery

How to find all elements whose attribute value starts with certain characters?


To find out all elements whose attribute value starts with certain characters we can use ^= operator.

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

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

Above jQuery code block would first select all input element and then filter elements whose id attribute starts with "tx" that select only first input element as only first input "id" attribute starts with "tx" characters.

Attribute starts with

 Views: 1616 | Post Order: 22



Write for us