简体   繁体   English

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

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

After a click on my element i can display the path : 单击我的元素后,我可以显示路径:

console.log(e.path)

This gave me an array : 这给了我一个数组:

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

I want to find in this array if there is an element with class "c-block" with pure Javascript 我想在此数组中查找是否存在带有纯Javascript类“ c-block”的元素

Do you have any suggestion ? 你有什么建议吗?

Thanks 谢谢

Use the below code:- 使用以下代码:-

<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