dennwc / dom

DOM library for Go and WASM
Apache License 2.0
486 stars 59 forks source link

Getting element values? #6

Closed alvid-the-bot closed 6 years ago

alvid-the-bot commented 6 years ago

How does one get element values with this package?

I tried calling myElement.GetAttribute("value"), but that ended up returning an empty value, rather than the value of my input field.

Is this something that needs additional implementation? Happy to PR something if that's the case.

dennwc commented 6 years ago

I think the problem is that the value is not an HTML attribute, but a JS object field.

Try getting the original JS value and calling Get on it:

myElement.JSRef().Get("value")

As an alternative, check how Input element does this.

dennwc commented 6 years ago

I'm assuming an issue was resolved. Feel free to reopen.

HarishHary commented 5 years ago

Trying to do the same thing but I think I missing something, any insight ?

input := dom.Doc.GetElementById("input")
btn := dom.Doc.GetElementById("btn")
btn.AddEventListener("click", func(_ dom.Event) {
    dom.ConsoleLog(input.JSValue().Get("value"))
})

Can you provide an example ? Seems like the example you gave only create elements so they are already there as Inputs and Buttons.