How to querySelector elements of an element's DOM using Polymer -
i have element :
<dom-module id="x-el"> <p class="special-paragraph">first paragraph</p> <content></content> </dom-module>
and use like
<x-el> <p class="special-paragraph">second paragraph</p> </x-el>
in imperative part:
polymer({ is: 'x-el', ready: function () { /* select .special-paragraph in light dom e.g. 'second paragraph' */ polymer.dom(this).queryselectorall('.special-paragraph'); /* select .special-paragraph in local dom e.g. 'first paragraph' */ polymer.dom(this.root).queryselectorall('.special-paragraph'); /* how can select .special-paragraph in both light dom , local dom ? */ } });
is possible using polymer built-in's ? or should use default dom api ?
polymer not provide helper function or abstraction list nodes both light and local doms.
if require functionality, can use this.queryselector(selector)
.
on side note, aside polymer.dom(this.root).queryselectorall(selector)
method, polymer provides $$
utility function helps in accessing members of element's local dom. function used follows:
<dom-module id="my-element"> <template> <p class="special-paragraph">...</p> <content></content> </template> </dom-module> <script> polymer({ is: 'my-element', ready: { this.$$('.special-paragraph'); // return <p> in local dom } }); </script>
note that, unlike queryselectorall
, $$
function returns 1 element: first element in local dom matches selector.
Comments
Post a Comment