jQuery > Selectors

element[attribute*='value'] - Attribute contains in jQuery

How to select elements whose attribute value contains certain characters

To find out elements form the web page whose a particular attribute contains certain characters, we can use Attribute contain selector.

    <input id="NameTxtFirst" type="text" />
<input id="NametxtLast" type="text" /> <input id="FirstName" type="text" /> <input id="btnTest" type="button" value="Button" /> <script> $(function () { $("input[id*='txt']").css("border", "1px solid red"); }); </script>

Above jQuery code first select all input elements and then filter them based on id value that contains "txt" characters.

In above case, only the second input element will get selected (and applied with border style) as only second input element has id = "NametxtLast" that has "txt" characters in between. Notice that the first element also has id = "NameTxtFirst" howver this contains capital "Txt" so this element will not get selected. The selectors are case sensitive.


 Views: 12057 | Post Order: 18

Write for us

Hosting Recommendations