如何使用原型获取锚标记的父ID? [英] How to get parent id of an anchor tag using prototype?

查看:98
本文介绍了如何使用原型获取锚标记的父ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Event.observe(window, 'load',
function() { 

    $$('a.tag_links').each(function(s) {
        //alert(s.parent.parent.id); //How to get id of its parent to parent
    });
}
);

我想获取父元素的ID。

I want to get the id of the parent element.

结构就像这样。

 <div class="home-page" id='entity-1'>
    <div class="index-page-category">

    <a href="/entities/category/food" class="tag_links">food</a>

</div>

结果应该是实体-1

推荐答案


Like this:

    $$('a.tag_links').each(function(s) {
        var parentid = $(s).up('div').id;
    });

这篇关于如何使用原型获取锚标记的父ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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