开发者

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

开发者 https://www.devze.com 2023-03-04 17:31 出处:网络
What is the best way to select an element that does not contain a number? eg $(\'div\').not(\":contains(\'1\')\").not(\":contains(\'2\')\").开发者_如何学Gonot(\":contains(\'3\')\")...;

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

eg

$('div').not(":contains('1')").not(":contains('2')").开发者_如何学Gonot(":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


Without using a plugin you can just use filter.

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

Proof


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消