Alex Rivera | Logout

How to find the parent element using javascript

Asked 2010-03-16T12:38:28.037
52

I want to change the background color of the table cell when radio button inside the cell is clicked.

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

How to get the parent element reference?

Edit
Report

1 Answer

129

Using plain javascript:

element.parentNode

In jQuery:

element.parent()
answered 2010-03-16T12:41:40.673

Your Answer