You already have some very good answers, I will only suggest a force to create a collection of objects based on the intended verification, to dynamize your practical scenario:
JSFiddle Example
// recolhe elementos que só contém números
var soNumeros = $('a').filter(function() {
return /^[0-9]*$/.test( $(this).text() );
});
// realiza algo com a colecção de objectos gerada
soNumeros.addClass('bubu');
Result of adding CSS class bubu
that changes the link formatting:
Byevolvingthepracticaluseofthiscode,wecaninvolvethesameinafunctionthatallowsustousethismethodforotherscenarios:
Example in JSFiddle
/* Procura elementos que contenham X
*/
function procura (ele, pattern) {
return ele.filter(function() {
return pattern.test( $(this).text() );
});
}
// realiza algo com a colecção de objectos gerada
soNumeros = procura($('a'), /^[0-9]*$/);
soNumeros.addClass('bubu');
In this way you can pass the desired selector and RegExp to be used.