Omnimaga

General Discussion => Technology and Development => Web Programming and Design => Topic started by: Sorunome on April 01, 2012, 02:47:44 pm

Title: Javascript mousetest
Post by: Sorunome on April 01, 2012, 02:47:44 pm
Well, I got this problem with javascript, I have to test if the mouse is over a element, but it must be in a if-condition.
Somehow this doesn't work: if (!document.getElementById('buttons').onmouseover)
Please help me!
Title: Re: Javascript mousetest
Post by: Deep Toaster on April 01, 2012, 02:50:03 pm
if (!document.getElementById('buttons').onmouseover) tests if the onmouseover property of #buttons is defined, not whether it's triggered or not. Basically, it tests if the browser is going to do something when the user mouses over.
Title: Re: Javascript mousetest
Post by: Sorunome on April 01, 2012, 03:52:51 pm
Ah, I get that. How do I do then what I really want?
Title: Re: Javascript mousetest
Post by: Eeems on April 01, 2012, 06:27:10 pm
You could have onmouseover set a variable and onmouseout unset it.
Kind of like what was suggested here: http://www.sitepoint.com/forums/showthread.php?572033-Determine-if-mouse-is-over-an-element
I'll look around and see if there is a simpler way.

If you want to do a lot of tests I'm sure there is a way you can use this: http://www.permadi.com/tutorial/cssGetElementUnderMouse/index.html