如何从锚子中获取父div id [英] How to get the parent div id from the anchor child

查看:82
本文介绍了如何从锚子中获取父div id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="wizard-rules" id="wizard-rule">If <a href="#" onclick="alert(this.id)" id="dashboard-rule-2" class="highlight">ALL DASHBOARD</a> encounters an error</div>

这里我想获得div id wizard-rule onclick on anchor标签。我怎么能这样做?

Here i want to get the div id wizard-rule onclick on the anchor tag. how can i do that?

锚标记现在只是获取锚标记本身的id。但不是其父元素的id。

the anchor tag now is just getting the id of the anchor tag itself. but not the id of its parent element.

推荐答案

使用 parentNode 来访问 id

<div class="wizard-rules" id="wizard-rule">If <a href="#" onclick="alert(this.parentNode.id)" id="dashboard-rule-2" class="highlight">ALL DASHBOARD</a> encounters an error</div>

这篇关于如何从锚子中获取父div id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆