bjork24 bjork24 - 9 months ago 44
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:


<input type="text />

this.disabled = false


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
. I want my tag's DOM API to reflect its state, but can't figure out what I'm missing here.

Answer Source

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:


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