What is the best way to remove all tabindex attribute to html elements?

user742102 picture user742102 · Jun 26, 2012 · Viewed 20.8k times · Source

What is the best way to remove all tabindex attributes from html elements? GWt seems to put this attribute even it is not set anywhere in the code. It sets tabindex to -1.

I have the code below as working but it is tedious because I have to search every element according to its tag name and that slows the page loading. Any other suggestions? I'd prefer the solution not use javascript, as I am new to it.

        NodeList<Element> input =  this.getElement().getElementsByTagName("input");

        if(input.getLength()>0)
        {
            for(int i=0; i<=input.getLength(); i++)
            {

                    input.getItem(i).removeAttribute("tabIndex");

            }

        }
        NodeList<Element> div =  this.getElement().getElementsByTagName("div");

        if(div.getLength()>0)
        {
            for(int i=0; i<=div.getLength(); i++)
            {

                    div.getItem(i).removeAttribute("tabIndex");

            }

        }

Answer

Danny picture Danny · Jun 26, 2012

I'm not entirely sure what you are asking then. You want to remove the tab index attribute. You either:

  • set the tabindex attribute to -1 manually in the HTML.
  • use the code you already have.
  • or use the simplified JQuery version in the other thread.

Perhaps I have misunderstood what you are trying to achieve?

EDIT

Okay perhaps this:

$(document).ready(function(){
    $('input').removeAttr("tabindex");
});

This should remove it rather than set it to -1... hopefully. Sorry if I've misunderstood again!

JQuery removeAttr Link