How to find parent element using javascript

I want to change the background color of a table cell when the radio button in the cell is pressed.

<table> <tr> <td align="center"> <input type="radio" value="foo" onclick="this.parentElement.style.background-color='red';" /> </td> </tr> </table> 

How to get a link to the parent element?

+49
javascript jquery html
Mar 16 '10 at 12:38
source share
2 answers

Using simple javascript:

 element.parentNode 

In jQuery:

 element.parent() 
+125
Mar 16 '10 at 12:41
source share

Use the change event to select:

 $('#my_select').change(function() { $(this).parents('td').css('background', '#000000'); }); 
+2
Mar 16 '10 at 12:43
source share



All Articles