call jQuery within a javascript function using a 'this' pointer
- <html>
- <head>
- <style type="text/css">
- .selected{
- background-color: red;
- }
- </style>
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <script>
- function click(cell){
- alert(cell);
- if (cell == 3)
- jQuery(this).toggleclass("selected");
- }
- </script>
- </head>
- <body>
- <table border="1px">
- <tr>
- <td onclick="click(1)">Cell 1</td>
- <td onclick="click(2)">Cell 2</td>
- <td onclick="click(3)">Cell 3</td>
- </tr>
- <tr>
- <td onclick="click(4)">Cell 4</td>
- <td onclick="click(5)">Cell 5</td>
- <td onclick="click(6)">Cell 6</td>
- </tr>
- </table>
- </body>
- </html>
I would like for jQuery to change the class of the <td> cell that I click. I need the jQuery inside of a function, since I only want it to toggle depending on a passed in parameter. My code doesn't seem to work though. What am I doing wrong?
Thanks