Click here to Skip to main content
15,913,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to select html element using jQuery selectors.

i use

$("p[title|='Tomorrow']").css("background-color", "yellow");});

$("p[title^='Tomorrow']").css("background-color", "yellow");});

but. both gives the same result. then why use |= selector.

What I have tried:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p[title|='Tomorrow']").css("background-color", "yellow");});  
</script>
</head>
<body>

<p title="Tomorrow">This is a paragraph.</p>
<p title="tomorrow">This is a paragraph.</p>
<p title="Tom">This is a paragraph.</p>
<p title="See You Tomorrow">This is a paragraph.</p>
<p title="Tomorrow-the day after today">This is a paragraph.</p>

<p>This selector selects all elements with a title attribute value equal to 'Tomorrow', or starting with 'Tomorrow' followed by a hyphen.</p>

</body>
</html>
Posted
Updated 17-Mar-20 20:58pm
v2

1 solution

See here: jQuery Selectors[^] - the difference is subtle, but for the data you are processing, it probably does give the same result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900