I'm trying to access the text of the current (this
) element from within an event handler created with scalatags. Here is what I tried:
val onChange = {(e: HTMLElement) =>
number() = e.textContent.toInt
}: js.ThisFunction
input(`type`:="number", onchange := onChange).render
When I debug the above code, nothing is being passed into the onChange
function. Specifically, if I put this into the function body: js.Dynamic.global.alert(JSON.stringify(e))
, it prints {}
. Also, I get an error that e.textContent
is null. How do I get it to pass in the javascript this
element?
I got some clarification on scala.js gitter, and it turns out you can access the element from within a closure like so: