Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Best practice: Remove active state from dropdown menu Re: Best practice: Remove active state from dropdown menu

#105086
littleGiant
Member

That is indeed a better solution than remembering the last element clicked. Thank you kgscott.

I adapted your solution so a click on the document removes the “active” class on the button. You have to keep event bubbeling in mind though. Without event.stopPropagation(); both handlers would be fired in sequence, resulting in an immediate removal of the active class (document handler is fired second) just after its addition (button handler is fired first).

http://jsfiddle.net/RU83L/4/

However, could this be refered to as best practise? Now every click causes a query for “.dropdown-button.active” within the DOM, right?