繁体   English   中英

使用纯Javascript在HTML元素数组中查找元素

[英]Find element in array of HTML element with pure Javascript

单击我的元素后,我可以显示路径:

console.log(e.path)

这给了我一个数组:

[i.fi.fi-bubble, button.c-block, div, body.u-help, html, document, Window]

我想在此数组中查找是否存在带有纯Javascript类“ c-block”的元素

你有什么建议吗?

谢谢

使用以下代码:-

<script>
var array = ["i.fi.fi-bubble", "button.c-block", "div", "body.u-help", "html", "document", "Window"];
var index = array.filter(value => /c-block/.test(value));
console.log(index.length);
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM