tags:

views:

5062

answers:

4

Hey all,

I need to get the "td" element of a table. I do not have the ability to add a mouseover or onclick event to the "td" element, so I need to add them with JQUERY.

I need JQUERY to add the mouseover and onclick event to the all "td" elements in the table.

Thats what I need, maybe someone can help me out?

A: 

There are likely many td elements in the table. To add a click event to all of the td elements, use:

$("td", "#theidofyourtable").click(yourevent);
Isaac Cambron
+16  A: 
$(function() {
    $("table#mytable td").mouseover(function() {
        //The onmouseover code
    }).click(function() {
        //The onclick code
    });
});
Justice
A: 

Using jQuery Selectors and Events you should be able to do something like:

    $("td").click(function () { 
      $(this).addClass("hilite"); 
   });
Mads Hansen
A: 

Work off of the following code to get you started. It should do just what you need.

$("td").hover(function(){
   $(this).css("background","#0000ff");
},
function(){
  $(this).css("background","#ffffff");
});

You can use this as a reference, which is where I pulled that code.

mwilliams