Home >>jQuery Tutorial >jQuery [attribute^=value] Selector

jQuery [attribute^=value] Selector

jQuery [attribute^=value] Selector

jQuery [attribute^=value] selector in jquery is used to selects each element with a specific attribute, with a value beginning in a specific string.

Syntax:

$("[attribute^='value']")

Parameter Values

Parameter Description
attribute It is a Required parameter and used to specifies the attribute to find
value It is a Required parameter and used to specifies the string the value should begin with

Here is an Example of jQuery [attribute^=value] Selector:


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input[name^='nation']").css("background-color", "#4796d6");});
</script>
</head>
<body>
<input name="nationality" type="text" value="Indian">
<input name="nation" type="text" value="Hindi">
<input name="country" type="text" value="India">
</body>
</html>

Output:

No Sidebar ads