Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

verifying if I'm hover an element

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
Hallo,

is it possible to verify if I'm hovering an element with the mouse, by knowing its class (not the id)?

thanks
 
Check out faq216-6104 for how to get elements by their classname, and then loop over them attaching an onmouseover event handler.

If you're using a JS framework such as prototype, this is even easier:

Code:
$$('.theClassname').each(function (el) {
  el.observe('mouseover', callBackFunc);
});

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Billy for the answer,

the first part is very clear, the second one I'm not sure that I understand: do you mean looping through the elements and modifying their tags by adding an onmouseover="myfunction()"...?

I'm not sure this will work, bceause the elements in my page are added dinamically by server scripts (that I cannot change), I think with Ajax or ASP.NET. Is there not a way to find out if I'm over them without needing to alter their tags, meaninng: whitout having to use the onmouseover event handler?

thanks
 
Yes... but it would be such a bad solution, really unworkable, especially if there are many elements on the page.

It'd be basically attaching an onmousemove event to the document, and every step looping through all elements determining whether the cursor is over each. Ugly, ugly, ugly - you don't want to do that.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top