jquery clickout svg

Feb 04, 2011 13:49

I needed to hide something when user clicked outside of it.
Two problems:
1) How to know if they clicked outside?
2) I have an SVG graphic on page. Click event does not get registered when it's on an SVG.

Solution:
Turns out that mouseup does get registered, even though click doesn't.
$(document).mouseup( function (event) { if (!$(event.target).closest('#element').length) $('#element').html('');
This hides #element when the user clicks outside of it, even if the click landed on an SVG.

dev

Previous post Next post
Up