We dynamically create the components, assign the class like the html above.
When click on the Primary button, we change their class for warning.
When click on the Danger button, we change their class for info.
if body, err := doc.Body(); hogosuru.AssertErr(err) {
//lets create some button design with bulma
if div, err := htmldivelement.New(doc); hogosuru.AssertErr(err) {
if list, err := div.ClassList(); hogosuru.AssertErr(err) {
list.Add("buttons")
}
if buttonprimary, err := htmlbuttonelement.New(doc); hogosuru.AssertErr(err) {
buttonprimary.SetTextContent("Primary")
//we get the class list attribute
if list, err := buttonprimary.ClassList(); hogosuru.AssertErr(err) {
list.Add("button")
list.Add("is-primary")
}
buttonprimary.OnClick(func(e event.Event) {
if list, err := buttonprimary.ClassList(); hogosuru.AssertErr(err) {
list.Remove("is-primary")
list.Add("is-warning")
}
})
div.Append(buttonprimary.Element)
}
if buttondanger, err := htmlbuttonelement.New(doc); hogosuru.AssertErr(err) {
buttondanger.SetTextContent("Danger")
//we get the class list attribute
if list, err := buttondanger.ClassList(); hogosuru.AssertErr(err) {
list.Add("button")
list.Add("is-danger")
}
buttondanger.OnClick(func(e event.Event) {
if list, err := buttondanger.ClassList(); hogosuru.AssertErr(err) {
list.Remove("is-danger")
list.Add("is-info")
}
})
div.Append(buttondanger.Element)
}
body.Append(div.Element)
}
}
Click on 2 buttons
How to hide a component?
We can hide components with the style directive "Display:None".
To hide a button:
if css,err:=buttondanger.Style();hogosuru.AssertErr(err) {
css.SetProperty("display", "none")
}
Access to attributes
If you want create an input checkbox element, you need write
if input, err := htmlinputelement.New(d);hogosuru.AssertErr(err) {
input.SetAttribute("type", "checkbox")
}
Style can be changed with the SetProperties and RemoveProperties of the
You can Modify/Set the attributes of elements with the corresponding method available on