Javascript examples for jQuery Selector:attribute value starts with
The [attribute^=value] selector selects elements whose attribute is beginning in a string.
Parameter | Description |
---|---|
attribute | Required. attribute to find |
value | Required. string to begin with |
The following code shows how to select all <input> elements with a name attribute that starts with "test":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input[name^='test']").css("background-color", "yellow");}); </script>/*ww w . ja v a 2s. c o m*/ </head> <body> <input name="test" type="text" value="Chinese"> <div name="test" ></div> <input name="country" type="text" value="test"> <input name="novalue" type="text" value="no value"> </body> </html>