简体   繁体   中英

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:

<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:

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

You can also select a specific keyframe with

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

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

document.querySelectorAll('[keyframe]')     

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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