简体   繁体   English

获取所有具有属性x的元素

[英]get all elements that have attribute x

Im having trouble searching for this on the polymer docs. 我在聚合物文档上搜索时遇到了麻烦。 I was wondering if anyone here can point me to or show me an example of a way to get all elements that have a particular attribute. 我想知道这里是否有人可以指向我或向我展示如何获取具有特定属性的所有元素的示例。 For instance: 例如:

the component: 组件:

<polymer-element name="prpl-inview" attributes="">
    <template class="{{count}}">
        <link rel="stylesheet" href="prpl-inview.css">
        <content select="*"></content>
    </template>
</polymer-element>

and the element in the dom: 以及dom中的元素:

<prpl-inview>
    <h1>Misc element not important</h1>
    <div keyframe="20">get this element</div>
</prpl-inview>

I want all the elements with attribute keyframe but I dont care about the other elements. 我希望所有具有属性关键帧的元素,但我不在乎其他元素。 If this makes any sense. 如果这有意义。

你可以做:

var elems = document.querySelectorAll("[keyframe]");

Use the queryselector: 使用queryselector:

var elementList = document.querySelectorAll('[keyframe]');

You can also select a specific keyframe with 您还可以选择一个特定的关键帧

var element = document.querySelector('[keyframe=20]');

您可以使用普通的DOM querySelector吗?

document.querySelectorAll('[keyframe]')     

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

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