Konstantin Solomatov
Konstantin Solomatov

Reputation: 10352

How to make HTML element focusable with GWTQuery

I am using GWTQuery for low level DOM programming. I have several div elements which need to receive focus so I want to make them focusable. Is there a way to make them focusable with GWTQuery? Or may some other way to do so.

Upvotes: 0

Views: 556

Answers (3)

jdramaix
jdramaix

Reputation: 1104

As Jean-Michel Garcia said, to make a DOM element focusable, you have to use/set the tabindex attribute of this element. The tabindex attribute specifies the tab order of an element and make it focusable.

You can do that using gwtquery :

$("#myDiv").attr("tabindex", 1);

you can replace the value '1' by any integer you want. It is just the tabbing order of the element (1 is the first). if you set -1, the element can't be tabbed on via the keyboard, but can be focused programmatically using either

element.focus();

or via GwtQuery :

$("#myDiv").focus();

Upvotes: 0

Tomasz Gawel
Tomasz Gawel

Reputation: 8520

none of these work?

//Gwt only
DOM.getElementById("myDiv").focus();

//GQuery        
$("#myDiv").focus();

Upvotes: 0

Jean-Michel Garcia
Jean-Michel Garcia

Reputation: 2389

This is plain GWT (not GWTQuery).

Maybe using something like :

DivElement div = Document().get().createDivElement();
div.scrollIntoView();

This method crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop properties of each scrollable element to ensure that the specified element is completely in view. It adjusts each scroll position by the minimum amount necessary.

You can also try using tabIndex.

Take a look here : https://stackoverflow.com/a/3656524/921244

Upvotes: 1

Related Questions