amateur
amateur

Reputation: 44673

find element based on tabindex

Using jquery or javascript, how can I find the input element in the DOM that has a particular tabindex set to it, eg.

<input id="txtInput" type="text" maxlength="5" tabindex="7">

I would want this element returned if I was searching for the element with tabindex = 7.

Upvotes: 15

Views: 26318

Answers (4)

Charles
Charles

Reputation: 71

Just using JavaScript:

document.querySelectorAll("input[tabindex='7']");

And if you want all elements, not just inputs, with a tabindex attribute of seven:

document.querySelectorAll("[tabindex='7']");

However, MDN recommends avoiding tabindex values greater than zero as it may be confusing, especially for those using screen readers.

Upvotes: 0

Nalum
Nalum

Reputation: 4223

You can get it with the following jQuery

$('input[tabindex=7]')

Upvotes: 20

Jakub Roztocil
Jakub Roztocil

Reputation: 16252

You can find the element by an attribute selector:

$('[tabindex=7]')

Upvotes: 8

pimvdb
pimvdb

Reputation: 154968

With the attribute selector:

$("[tabindex=7]") // all elements with tabindex=7

Upvotes: 8

Related Questions