Getting a Value

getElementById gives us a value of type option(Webapi.Dom.Element.t), where the t stands for “type.” This is a generic element. It is the “parent” of more specific types of elements such as HTML elements or SVG elements, and its interface doesn’t include any functions for obtaining an element’s value attribute. The interface for HTML elements does have such a function. Since we are dealing with an HTML element, we’ll use unsafeAsHtmlElement to tell ReasonML to treat this element as an HTML element.

Why is it Called Unsafe?

images/aside-icons/info.png

The function name unsafeAsHtmlElement contains unsafe because it calls JavaScript directly and will work ...

Get Web Development with ReasonML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.