javascript - :focus pseudo selector style not being removed when a new tab is opened , even though blur event is fired -


i working on nav menu contains external url links, there focus styles associated navigation menu , menu item gets background when focused. if item, anchor points external link, clicked, opens new tab , displays page represented external link. problem that, though new tab opened when user comes original tab, can still see background behind clicked nav menu item. there no :active styles associated menuitem.

i created example in js fiddle enumerate problem:
https://jsfiddle.net/bc5yu44v/2/

<body>   <a id="selectme" href="www.google.com" target="_blank" onblur="changetext()">clcik here</a>    </body> 

here can see after new tab opened clicking anchor tag , anchor tag not loose :focus style, can see text changed , indicating onblur event fired.

can body point me on how remove :hover style?, possible using pseudo selector or can achieved writing js , toggling classes?. have restriction of not using jquery too. have tested in chrome , firefox only.

this happens because navigating away page causes page lose focus, takes focus away element within page may have been in focus @ time, why element's blur event fired.

once navigate page (or in case tab/window containing page), focus returned element in focus @ time, , if had onfocus event handler on element, fire well. element not lose focus permanently between page or window focus/blur events. similar behavior can observed switching windows, switching tabs, or opening , closing start if you're on windows.

you can force element lose own focus explicitly calling .blur() @ end of event handler, not onblur event handler onclick event handler instead, because otherwise element defocus when switch tabs, etc.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -