Solution 1 :

Just replace the selector by the filter:

$(document).ready(function() {
  $('a').filter(function() { 
    return $(this).text() === "Products"; 
  }).attr('href', '/category/All-Products')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#">Products</a> 
<a href="#">My Products</a>

Problem :

Can someone please demonstrate for me how to implement this filter jquery into the below scenario i have. As i want it to find the link that contains exactly the word “products”

$('a').filter(function(index) { return $(this).text() === "Products"; });

Note the code below changes BOTH links, not just the first

$(document).ready(function() {
  $("a:contains('Products')").attr('href', '/category/All-Products')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#">Products</a> 
<a href="#">My Products</a>

Comments

Comment posted by palaѕн

Not able to get what issue you are facing here. Could you please elaborate it more. Thanks!

Comment posted by minimal reproducible example

I made you a snippet to have a

Comment posted by LDS

$( “a” ) .filter(function( index ) { return $( “Products”, this ).length === 1; }) .attr(‘href’, ‘/category/All-Products’);

Comment posted by mplungjan

@LDS that would select

By