Great Question Great Question - 2 months ago 14
jQuery Question

CSS selector for "tabindex > 0" elements

I am trying to select all the elements which has tabindex greater than -1 (focus-able elements). So far this is what I came up with:

$element.find('[tabindex]:not([tabindex < \'0\'])');


It does not work but instead throws an error:

Error: Syntax error, unrecognized expression: [tabindex < '0']
at Function.Sizzle.error (vendor.js:1463)
...


This, however, works but itdoes not cover cases where tabindex < -1.

$element.find('[tabindex]:not([tabindex=\'-1\'])');

Answer

Selectors doesn't provide attribute selectors with numeric comparisons, and neither does jQuery.

In this specific case, I suppose you could just exclude elements with a tabindex starting with the - sign (in addition to excluding elements with a tabindex of 0):

$element.find('[tabindex]:not([tabindex="0"]):not([tabindex^="-"])');