0

I have such table in HTML:

<table>
    <tr>
        <td>Cell 1</td>
    </tr>
    <tr>
        <td>Cell 2</td>
    </tr>
    <tr>
        <td>Cell 3</td>
    </tr>
</table>

How to change cell's background on mouse move in this cell? If cursor moves away from the cell, background must stay, but if the cursor move to the other cell, it must reset background.

3
  • 1
    What exactly is your question about - the JS part, the CSS part...? At the moment, this looks like a "write the full code for me" type question. Commented Oct 11, 2010 at 11:22
  • 1
    Is a framework available? (jquery, prototype, mootools etc) Commented Oct 11, 2010 at 11:23
  • Frameworks is not used. It would be great if I could only use css. Commented Oct 11, 2010 at 12:00

1 Answer 1

1

since you need one cell highlighted, if you're including jQuery you could use this code.

(function() {

   var current_cell;

   $('td').bind('mouseenter', function() {
      if (current_cell) {
         current_cell.removeAttr('id');
      };
      current_cell = $(this);
      current_cell.attr('id', 'highlight');
   });
})();

and then just use a bit of css

td#highlight {
  background: ... ;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.