Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh the browser hover effect after a DOM change

I've got an element whose css is altered under :hover. I've also got some javascript that changes the height of the element. However if the javascript fires while the :hover state is active the state remains even though the height change moves the element out from underneath the mouse.

Also since the javascript is fired by a click event within the element. This effect occurs on touch screens too.

I want to know if there's some way of coping with this issue. Can I force the browser to re-calculate hover (or mouseover etc)? Looking at this question, I'm not optimistic.

I've created a fiddle to demonstrate the issue.

I guess if the worst comes to the worst I could do it all manually with classes, mouseenter, mouseleave and DOMAttrModified. But that sounds like a pain and may even be costly in terms of javascript (I'll have to manually identify whether the mouse sits within the bounds of my elements).

UPDATE

OK, so I really can't touch DOMAttrModified, the performance hit is massive.

like image 944
Aidan Ewen Avatar asked May 23 '14 13:05

Aidan Ewen


People also ask

How do you refresh a DOM element?

The location reload() method in HTML DOM is used to reload the current document. This method refreshes the current documents. It is similar to the refresh button in the browser.

How to detect changes in DOM?

“MutationObserver” is a Web API provided by modern browsers for detecting changes in the DOM. By using this API you can listen to changes in DOM, like added or removed nodes, attribute changes or changes in the text content of text nodes and make changes. Web apps are getting complex on the client-side nowadays.

How do you hover Javascript?

jQuery hover() Method The hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.


1 Answers

element.parentNode.replaceChild(element, element);

like image 115
Artemiy StagnantIce Alexeew Avatar answered Oct 27 '22 00:10

Artemiy StagnantIce Alexeew