You already have some very good answers, I’m just going to suggest a force to create a collection of objects based on the intended verification, to streamline your practical scenario:
Example in Jsfiddle
// 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 formatting of the link:
By evolving the practical use of this code, we can involve it in a function that allows us to make use of this method for other scenarios:
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');
This way you can pass the desired selector and Regexp to be used.
and if the following happens:
<a href="#">a1</a>
?– Felipe Avelar
Hello, actually in my case there is no such possibility... Can only have text or numbers, not numbers with texts!
– Wagner'