Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .not(":contains('<<any number>>')")

What is the best way to select an element that does not contain a number?

eg

$('div').not(":contains('1')").not(":contains('2')").not(":contains('3')")...;

Sorry chad I have worded my example wrong.

I have about 20 divs selected already, and need to then filter out the ones that dont contain a number to pass them into a function.

I have tried gettin your example to work like

if($(this:+'regex(html, #^0-9]')).length <1 {

but having no luck

like image 734
callum.bennett Avatar asked May 10 '11 14:05

callum.bennett


2 Answers

Without using a plugin you can just use filter.

$('div').filter(function() {
   return !/[0-9]/.test( $(this).text() );
});

Proof

like image 190
Josiah Ruddell Avatar answered Sep 19 '22 20:09

Josiah Ruddell


Instead of getting all fancy with selectors, you can use .filter().

var re = /\d+/;

var $noNumbers = $('div').filter(function ()
{
    return !$(this).text().match(re);
});

Demo: http://jsfiddle.net/mattball/3sRmt/

like image 30
Matt Ball Avatar answered Sep 20 '22 20:09

Matt Ball