Element attribute

Hello, I’ve set a “key-value” attribute in an element. How can I reference / get this attribute in a Javascript function?

I have several buttons, and I need that each one hide/shows a different target. I can store the target id in the key/value of the buttons, but I need to get these values in the JS functions.

Thanks in advance, Alejandro Godoy.

You should store the ID in the “Unique Element ID” section of the Identity inspector. If you are going to look up that way, then the code to get an attribute is just:

var myElement = hypeDocument.getElementById("myID");
var myValue = myElement.getAttribute("myAttribute");
2 Likes

Perfect, thank you!

Another thing to consider. Once you start using your code logic on multiple layouts or scenes the ID approach runs into the limits of HTML demanding ID’s to be unique across all of the HTML page. The alternative would be to target elements by there class element.

1 Like