I'm trying to retrieve properties on various elements within a text that is loaded through inner-h-t-m-l but I fail to get just one specific element.
Here is my code:
<template>
<iron-ajax
auto
url="[[some/path/url.html]]"
handle-as="text"
last-response="{{inputText}}"></iron-ajax>
<div class="textcontent" inner-h-t-m-l="{{inputText}}"></div>
</template>
<script>
Polymer({
is: 'text-page',
ready: function() {
var test = document.getElementsByClassName("author");
console.log(test);
}
});
</script>
So I have two questions about this:
- Is this the best way to load an html page into a Polymer element?
- The output of the console.log is an array that looks like this:
HTMLCollection[0] 0: span.author 1: span.author 2: span.author length: 3 __proto__: HTMLCollection
This is correct, there are 3 elements with class-name "author". But when I do the same thing with console.log(test[0])
in order to get just the first one, I get "undefined"
as output. How do I get just the first one, and more importantly, the value of that span
?