2

I'm using Dart and Polymer 1.0.0-rc.9. I have my own element (simplified here of course):

<dom-module id="something">
 <style>
 </style>

 <template>
   <paper-slider id='myslider'></paper-slider>
   <div id='mydiv'></div>
 </template>
</dom-module>

On the Dart side, if I do:

 var div=queryselector('#mydiv')

it returns null.

I then set:

 <template is='dom-bind'>

it finds it. But that creates errors, which say I must use a simple template.

So how do I find my <div> element?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Lymp
  • 933
  • 1
  • 7
  • 20
  • Your question doesn't show how things are connected. Can you please add the HTML of your index.html and the Dart code of your `something` element. Hint: Custom elements must have a `-` in the name like ``. Where is this code `var div=queryselector('#mydiv')` called from? – Günter Zöchbauer Jan 08 '16 at 20:03
  • See also http://stackoverflow.com/questions/29629492/how-to-query-elements-within-shadow-dom-from-outside-in-dart and http://stackoverflow.com/questions/32703490/what-are-the-different-ways-to-look-up-elements-in-polymer-1-0/32703491#32703491 – Günter Zöchbauer Jan 08 '16 at 20:04
  • 1
    Many thanks. This one worked for me `var listdivs = Polymer.dom (this.root) .querySelectorAll('div');` cheers, s – Lymp Jan 09 '16 at 14:41

2 Answers2

1

Use

var listdivs = Polymer.dom (this.root).querySelectorAll('div');
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

It's likely because you're calling

 var div=queryselector('#mydiv')

outside that Polymer Element. I'm not sure, but I'm guessing the ID's within the 'something' element are only available from within it.

Your best course of action would be to give your element an ID wherever you declared it.

<something id="something"></something>

then access the children of the element

 var elm =queryselector('#something');
var children = Polymer.dom(elm).children[1];
Chris W
  • 785
  • 8
  • 18