How to make elements like div, table and span support focus/blur?

Since we know that elements such as input, button and select support focus/blur how can I make other elements like div, b, ul and span to accept blur and being focuseable? How to make these elements support focus and blur events?

»Javascript @migambijee

» 1 answer  » 41 views   

Add photos

Themeeky • 1 month ago
The solution is simple. Just use HTML-attribute tabindex. Because any element which has tabindex accepts both focus/blur events. tabindex-attribute contains the number (tabindex="2", tabindex="3") so that Tab key can be used to focus to each element which has tabindex. How does tabindex work logically? When you press Tab key, it moves from one element to another but according to number in the attribute. But pay attention to these special values below: tabindex="0" when an element has 0 as value that element is not treated as tabindex, that's why it comes after all elements with tabindex >=1. tabindex="-1" This value is for programming reason which means it works on when you you adding more javascript codes. Briefly, The Tab element doesn't count such elements but method element.focus() works. <div tabindex="1"> <span tabindex="0">Span 0</span><br> <span tabindex="2">Span 2</span><br> <span tabindex="3">Span 3</span><br> <span tabindex="4">Span 4</span><br> </div>  »

0  Dislike  •  Reply

Back to top

[SHARE THIS POST]: The post's archived Spread it to others!

Posted under this donnektish »
This community is about sharing contents such as questions and answers discussing about Javascript and TypeScript, ES5, ES6
58 people joined this donnektish

Maintain social distancing, to avoid Covid19