How to mix this javascript toggle with window mouseup event

Hi guys,

I’ve got struck. I’m trying to do something like when you clicking on the hamburger button of this forum. It’s toggled a div, and it still works with the window mouseup event presented.

But my code here isn’t worked. What’s that I’ve done wrong.

<!DOCTYPE html>
<html>
	<head>
		<style>
			#showme { display: none; }
		</style>
	</head>
	<body>
		<div id=button>Button</div>
		<div id=showme>
			I'm revealed!
		</div>
		<script>
			var d = document, w = window
			  , b = d.getElementById('button')
			  , a = d.getElementById('showme')
			  ;

			b.addEventListener('click', function() {
				if (a.style.display !== 'block')
					a.style.display = 'block';
				else
					a.style.display = 'none';
			});
			w.addEventListener('mouseup', function(e) {
				a.style.display = 'none';
			});
		</script>
	</body>
</html>

Thank you,

Never mind,

It needs window onload event to get this done. Not this one…

No it doesn’t. That event is almost never needed - I have come across exactly once where a script needed it and this isn’t that one.

Yes, you’re right. It doesn’t need it.

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.