JavaScript element.tabIndex Property

You are Here:

JavaScript element.tabIndex Property

The element.tabIndex property gets or sets the value of the tabindex attribute of an element.

The tabindex attribute specifies the tab order of an element.

Get the tabIndex

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Press 'Tab' key to navigate through input.</p> <p>Name</p> <input type="text" value="John" tabindex="3"> <p>Age</p> <input type="text" value="45" tabindex="1" autofocus> <p>Gender</p> <input type="text" value="Male" tabindex="2"> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var elem = document.getElementsByTagName("input")[0]; function myFunction(){ x.innerHTML = "tabIndex = " +elem.tabIndex; } </script> </body> </html>

Syntax

element.tabIndex

Return Values

ValueExplanation
StringReturns the tab order (tabIndex) of the specified element.

Set the tabIndex

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Press 'Tab' key to navigate through input.</p> <p>Name</p> <input type="text" value="John"> <p>Age</p> <input type="text" value="45" autofocus> <p>Gender</p> <input type="text" value="Male"> <script> document.getElementsByTagName("input")[0].tabIndex = "2"; document.getElementsByTagName("input")[1].tabIndex = "1"; document.getElementsByTagName("input")[2].tabIndex = "3"; </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author