bjork24 bjork24 - 1 month ago 9
Javascript Question

Accessing a Riot.js tag's properties from the DOM

I'm playing with Riot.js and everything is working great. But let's say I have a page where I mounted this single tag:

<so-example>

<input type="text />

<script>
this.disabled = false
</script>

</so-example>


Let's say I want to query this element for one of its properties (e.g. if it's disabled). Neither of these two approaches work:


  1. document.getElementsByTagName('so-example')[0].disabled

  2. document.querySelector('so-example').disabled



Both of these statements return
undefined
. I want my tag's DOM API to reflect its state, but can't figure out what I'm missing here.

Answer

For anyone who finds themselves in the same situation, the answer is to query the _tag property on the element. To access the disabled property of the element I used in my original question, you could do this:

document.querySelector('so-example')._tag.disabled

And that should return the expected false. Anything that's defined on this within the component can be accessed this way.