Julius Babies
Julius Babies

Reputation: 1861

How can I access a custom HTMLElement Attribute in Typescript

I have a parser written in TypeScript, but there are important custom HTML attributes.

<span visible-language="en">...</span>

How can I read them? I can't just make the HTMLElement as a type of any and get it as an attribute because the attribute key contains a - which isn't allowed in TypeScript / JavaScript Syntax.

I don't use any frameworks, just plain TypeScript.

Upvotes: 1

Views: 2406

Answers (1)

<span visible-language="en" id="myAttrID">...</span>

const myAttr = document.getElementById("myAttrID") 
let getData = myAttr.getAttribute("visible-language");

Upvotes: 3

Related Questions