How to select all anchor tags with specific text

Given multiple anchor tags:

<a class="myclass" href="...">My Text</a>

How do I select the anchors matching the class and with some specific text. eg Select all anchors with the class:'myclass' and text:'My Text'


Solution 1:

$("a.myclass:contains('My Text')")

Solution 2:

You could create a custom selector similar to :contains for exact matches:

$.expr[':'].containsexactly = function(obj, index, meta, stack) 
{  
    return $(obj).text() === meta[3];
}; 

var myAs = $("a.myclass:containsexactly('My Text')");