github.com/primecitizens/pcz/std@v0.2.1/ui/html/utils.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build js 5 6 package html 7 8 import ( 9 "github.com/primecitizens/pcz/std/ffi/js" 10 "github.com/primecitizens/pcz/std/plat/js/web" 11 ) 12 13 type ElementFinder interface { 14 GetElementById(id js.String) web.Element 15 } 16 17 // FindElement by id. 18 func FindElement[ 19 T interface{ FromRef(js.Ref) T }, 20 F ElementFinder, 21 ](out *T, root F, id string) bool { 22 ref := root.GetElementById(js.NewString(id).Once()).Ref() 23 if ref.Undefined() { 24 return false 25 } 26 27 *out = (*out).FromRef(ref) 28 return true 29 }