Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why does this element with tabindex value of -1 still receive focus?

I am creating a UI for work which is controlled with a remote (only arrow keys), and In this one part of the UI, just one field which has the tabindex value set to '-1', still receive focus. What could cause this?

http://prntscr.com/gs878z

1 Answer

Steven Parker
Steven Parker
243,318 Points

Not only the tabindex value, but the lack of an href attribute should prevent it from receiving focus. But it could get it anyway because of some CSS rules (possibly that target one of the classes), or some JavaScript code, neither of which is shown here.

Exactly that's what I thought... apart from the JavaScript I wrote to try to get around this. There is no code which should send focus to that element.. So any other thoughts? Haha

Steven Parker
Steven Parker
243,318 Points

It would be necessary to examine all the code (JS, CSS, and the entire HTML) to determine other possible causes. And are there other inputs that can receive focus instead?

Yeah I guess you're right. I can't publicly share the code, So I guess I'll start searching for bugs lol. This will be a fun week