如何使用javascript查找父元素 [英] How to find the parent element using javascript
本文介绍了如何使用javascript查找父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< table> 我想改变表格单元格的背景颜色。 ;
< tr>
< td align =center>
< input type =radiovalue =foo
onclick =this.parentElement.style.background-color ='red'; />
< / td>
< / tr>
< / table>
如何获取父元素参考?
element.parentNode
$ h2_lin>解决方案
在jQuery中:
元素.parent()
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?
解决方案
Using plain javascript:
element.parentNode
In jQuery:
element.parent()
这篇关于如何使用javascript查找父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文