views:

65

answers:

2

Hello, I have this table. I want to change the color of a cell, from black to red, when i move over that cell, I'm using the .hover method, and i'm having trouble figuring out how to make work accordingly to what i need.

<html>
    <head>
    <script type="text/javascript" src="jquery-1.4.js"></script>

    <script>

    $board = $('#board')

    $(this).hover(function()
    {
        $('td').css('border-color', 'red');
    },
    function()
    {
        $('td').css('border-color', 'black')
    })

    </script>

    <style type="text/css">
    td
    {
        border-style:solid;
        border-color:black;
    }


    </style>


    </head>
    <body>
    <table id="board">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <input type="button" value="Shuffle" onclick="change()"/>
    </body>
</html>
A: 

Try this

$board.find('td').hover(function(){
    $(this).css('border-color', 'red');
},
function(){
    $(this).css('border-color', 'black')
})
PetersenDidIt
I added it but it didn't seem to highlight anything now.
Steffan
A: 

you could try something like:

<script type="text/javascript">

$(document).ready(function(){

    $("#board tr td").hover(function()
    {
        $(this).css('border-color', 'red');
    },
    function()
    {
        $(this).css('border-color', 'black')
    });
});

</script>

remember the type="text/javascript" on the script tag

when the page loads the $(document).ready function will be called, then it will set up the hover events.

when the mouse hovers over a td inside #board the first function will be called on this, the td you're hovering over. when the mouse moves out it will call the second function putting the border back to black.

John Boker
thanks!, that seemed to get it to work
Steffan
you're welcome! remember to mark this as the answer if it helped.
John Boker