If you are only bothered if the anchor's text contains a particular string, go with @Dave Morton's solution. If, however, you want to exactly match a particular string, I would suggest something like this:
$.fn.textEquals = function(txt) {
return $(this).text() == txt;
}
$(document).ready(function() {
console.log($("a").textEquals("Hello"));
console.log($("a").textEquals("Hefllo"))
});
Hello
Slightly improved version (with a second trim parameter):
$.fn.textEquals = function(txt,trim) {
var text = (trim) ? $.trim($(this).text()) : $(this).text();
return text == txt;
}
$(document).ready(function() {
console.log($("a.myclass").textEquals("Hello")); // true
console.log($("a.anotherClass").textEquals("Foo", true)); // true
console.log($("a.anotherClass").textEquals("Foo")); // false
});
Hello
Foo