-1

By focus, I don't just mean scroll to that section of the page. Is there a way to make the browser behave as if the user had clicked on that div? The use case here is that I want a user to be able to scroll in a div using the arrow keys, but the div appears on the click of another button which does not click the div itself, so attempting to scroll with the arrow keys does nothing since the main page is not scrollable and is "focused" by default. Obviously the .focus function does not work on divs so I am wondering how to do this!

  • This is NOT the same question as the one that it was marked as a duplicate of. There are links to similar questions in the answers to this one but currently this is marked as a duplicate of the wrong question
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • Your note that it's not a duplicate is incorrect as you've accepted an answer that is literally a copy of an answer in that question (even with a link). – freedomn-m Nov 07 '18 at 08:54

1 Answers1

1

You just have to add a tabindex attribute with value of -1 to the <div> according to this answer and it will work with the below code:

$('div').attr("tabindex", -1).focus();
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79