views:

27

answers:

2

How do I find the DIV in which my cursor is placed at any moment, so I can change the formatting of that area.

+4  A: 

I imagine what you are looking for is the CSS :hover pseudo selector. It is supported in almost every browser (In IE6 it only works on a elements). In your CSS file you could do something like this:

div:hover { background: red, border: solid 1px #000 }

Which would cause any div to change color when the mouse cursor is over the element.

You would of course scope it to just the divs you wanted to change:

#thisDiv:hover, .special:hover { background: blue }

For IE6 you can either choose not to support that functionality, or you can use javascript to add and remove .hover classes from the elements, then add that selector to your CSS rules as well.

Doug Neiner
+1 - Using CSS rather than javascript for this.
James Black
A: 

I'm not sure that anything exists to find that directly. You could update the formatting with onmouseover and onmouseout events for the divs.

Kaleb Brasee