javascript - which approach is more correct to get element in document with focus? -
i have went through couple of questions asked related , have found 2 common approach.
- have global element , update attaching onfocus() event each of element.
document.activeelement , have following code update element in case of old browser not support property
var focusedelement; document.addeventlistener("focus", function(e) { focusedelement = e.target; }, true); document.addeventlistener("blur", function(e) { focusedelement = null; }, true);
now question 1 more correct/easy/efficient approach of above two? why? all,
your solution 1 horribly inefficient. attaching event handler each , every (focusable) element on page when attach body itself? not correct/easy/efficient way sure. solution 2 looks pretty good.
Comments
Post a Comment