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

191 views   Javascript  2020.09.19


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?

Answers, ideas and Comments

» 1 idea

themeeky • 1 year 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 



In order to go deep, share any relevant idea or posting solution to some questions, You have to sign in or create a new account if you don't have one. And get Donnekted(connected)




Log in now  Join the Team

This site is for sharing topics, questions, answers, experiences or other contents related to different stuffs, especially technology. For existing users, They can make any topic(post) to discuss about in hope for ideas or any result from other people from different communities. In order to get involved, Get donnekted(connected) by Joining us here!

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


84 people joined this donnektish


Maintain social distancing, to avoid Covid19