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 specified attribute, with a value equal to a specified 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 used to Required parameter and used to specifies the string the attribute value should start 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(){
$("p[title|='one']").css("background-color", "#4796d6");});  
</script>
</head>
<body>
<p title="one">This is First paragraph.</p>
<p title="two">This is Second paragraph.</p>
<p title="three">This is Third paragraph.</p>
<p title="fourth">This is Fourth paragraph.</p>
<p title="one-para">This is Fifth paragraph.</p>
</body>
</html>

Output:

This is First paragraph.

This is Second paragraph.

This is Third paragraph.

This is Fourth paragraph.

This is Fifth paragraph.