1

What is the correct context to store the focus function of an HTMLElement in a variable?

I tried,

var elem = document.getElementById('elem');
var focus = elem.focus.bind(document); // focus() Illegal Invocation
var focus2 = elem.focus.bind(elem); // focus2() Illegal Invocation
s4san
  • 319
  • 2
  • 9

1 Answers1

-1

Wrap it into your own function:

var elem = document.getElementById('elem');
var focusElem = function(){ elem.focus(); };
focusElem();
meehocz
  • 174
  • 4