I have a link, and if you drag this link then release, the link will keep his active state.
Example: http://jsfiddle.net/Ek43k/3/
<a href="javascript:void(0);" id="foo" >Drag me</a>
#foo:active{
color:red;
}
How can I prevent this?
(Only in IE and FF)
Detach and reattach the link from the DOM tree to disable its active state. Do this when the drag ends and you’ve got this:
No need to mess with your HTML or CSS or do away with
:active. Seems to work in both FF and IE.Edit: I don’t usually write pure Javascript for DOM-handling so the quality of this might not be top notch, but here it is without jQuery:
I took care of a few issues that came to mind to make it fully plug-and-play. Tested in Opera, Chrome, Firefox and Internet Explorer.
Edit 2: Inspired by Chris, another way to apply the fix is to use the
ondragendattribute directly to connect thedeactivator(not tested):The downside is that it requires the
ondragendattribute with javascript to be specified on each link manually/explicitly. I guess it’s a matter of preference.Final (?) Edit: See comments for delegate/live versions of these and Chris’ answer.