查找DOM节点索引 [英] Finding DOM node index

查看:67
本文介绍了查找DOM节点索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到给定DOM节点的索引。这就像是做的相反的事情

  document.getElementById('id_of_element')。childNodes [K] 

我想提取 K 的值,因为我已经有引用子节点和父节点。我该怎么做?

解决方案

所有版本的Safari,FireFox,Chrome和IE> = 9: / p>

var i = Array.prototype.indexOf.call(e.childNodes,someChildEl);


I want find the index of a given DOM node. It's like the inverse of doing

document.getElementById('id_of_element').childNodes[K]

I want to instead extract the value of K given that I already have the reference to the child node and the parent node. How do I do this?

解决方案

The shortest possible way, without any frameworks, in all versions of Safari, FireFox, Chrome and IE >= 9:

var i = Array.prototype.indexOf.call(e.childNodes, someChildEl);

这篇关于查找DOM节点索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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