2

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.

WongKongPhooey
  • 398
  • 1
  • 5
  • 20
user1555245
  • 125
  • 2
  • 3
  • 12

4 Answers4

4

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();
KrishnaDhungana
  • 2,604
  • 4
  • 25
  • 37
1
$("#divVZITab").focus()

or

document.getElementById('divVZITab').focus();
Ullas
  • 11,450
  • 4
  • 33
  • 50
0

Try this:

$("#divVZITab[tabindex='-1']").focus();
codingrose
  • 15,563
  • 11
  • 39
  • 58
  • I tried a;; this but all failed... function setFocus() { debugger; $("#divVZITab").attr("tabindex",-1).focus(); window.location.hash = '#divVZITab' document.getElementById('divVZITab').scrollIntoView(); } – user1555245 Oct 25 '13 at 10:06
  • HI tried..3 solutions.... bt none of them is working!!!!!!!!!!! function setFocus() { $("#divVZITab").attr("tabindex",-1).focus(); window.location.hash = '#divVZITab'; document.getElementById('divVZITab').scrollIntoView(); } Please help here – user1555245 Oct 25 '13 at 10:15
0

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.

Community
  • 1
  • 1
Girish Sakhare
  • 743
  • 7
  • 14