简体   繁体   中英

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.

Thank you!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM