user1555245
user1555245

Reputation: 135

Focus on DIV on Page load

I'm using

$("#divVZITab").attr("tabindex",-1).focus();

On page load I want divVZITab to become the focus, it is in the center of page. So when page loads IE should automatically scroll to the center of the page & focus on the div. But it is not working.

Upvotes: 2

Views: 17008

Answers (4)

Kinjan Shah
Kinjan Shah

Reputation: 76

$("#divVZITab").focus()

or

document.getElementById('divVZITab').focus();

Upvotes: 1

KrishnaDhungana
KrishnaDhungana

Reputation: 2684

As you mentioned IE, I think that is the issue because I tried in jsfiddle and works fine. I tried in IE with tabindex="-1" and does not work but for positive (+ve) value of tabindex="1" it works. BTW run script after the DOM is ready.

HTML

<div id='divVZITab' tabindex="1">Test</div>

JavaScript

document.getElementById('divVZITab').focus();

Upvotes: 4

Girish Sakhare
Girish Sakhare

Reputation: 763

Is it possible to focus on a <div> using javascript focus() function?

please refer to second answer in the above link.

Hope that's the same stuff you trying to achieve.

Upvotes: 0

codingrose
codingrose

Reputation: 15699

Try this:

$("#divVZITab[tabindex='-1']").focus();

Upvotes: 0

Related Questions