7

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

callum.bennett
  • 678
  • 3
  • 12
  • 28

2 Answers2

8

Without using a plugin you can just use filter.

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

Proof

Josiah Ruddell
  • 29,697
  • 8
  • 65
  • 67
3

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/

Matt Ball
  • 354,903
  • 100
  • 647
  • 710