Reputation: 213
Currently I have a list like so:
<div class="list">
<div class="padding">
<div class="clickable-item">item 1</div>
</div>
<div class="padding">
<div class="clickable-item">item 2</div>
</div>
</div>
With the keyboard I would like to tab to the clickable-items one after another.
Currently it's tabbing through the 'padding' elements instead.
Is there any way I can tell the browser to ignore the padded parent and tab straight to the child?
Upvotes: 2
Views: 2975
Reputation: 6922
You can set the tabindex
attribute on the desired elements. The tab index number determines the order in which the elements are visited.
Edit: As FullOnFlatWhite and Graham Ritchie mentioned, it's generally better to use tab indices of zero (not positive), or use role="button"
on your div.
<div class="list">
<div class="padding">
<div class="clickable-item" tabindex="0">item 1</div>
</div>
<div class="padding">
<div class="clickable-item" tabindex="0">item 2</div>
</div>
</div>
Upvotes: 0
Reputation: 3672
Here's a few things to think about:
<div class="clickable-item" />
isn't indicating that it's a clickable item. See: Making a clickable <div> accessible through tab structure? on why using a div
isn't always the best solution and using a button
or a
tag is better for accessibility.tabindex="0"
on the elements.<div class"clickable-item" role="button" />
on your div in order to indicate that it is indeed something clickable.Upvotes: 3