Documentation
¶
Overview ¶
Package option provides constructors and methods for the HTML <option> element.
The <option> HTML element is used to define an item contained in a <select>, an <optgroup>, or a <datalist> element. As such, <option> can represent menu items in popups and other lists of items in an HTML document.
Index ¶
- Variables
- func New(nodes ...node.Node) *element
- func Option(value string, str string) *element
- func RawText(content string) *element
- func RawTextf(format string, args ...any) *element
- func Selected(value string, str string) *element
- func Static(content string) *element
- func Text(content string) *element
- func Textf(format string, args ...any) *element
- type Element
Constants ¶
This section is empty.
Variables ¶
var ( TagOpen = []byte("<option") TagClose = []byte("</option>") AttrValue = []byte(" value=\"") AttrDisabled = []byte(" disabled") AttrLabel = []byte(" label=\"") AttrSelected = []byte(" selected") )
Byte constants for HTML rendering.
Functions ¶
func New ¶
New creates a new option element with optional child nodes Example: option.New() Renders: <option></option>
func Option ¶
Option creates an option element with a value and display text. Uses text.Text which HTML-escapes the output. Example: option.Option("us", "United States") Renders: <option value="us">United States</option>
func RawText ¶
func RawText(content string) *element
RawText creates a new option element with raw text content. Uses text.RawText which is not HTML-escaped. Example: option.RawText("Option <em>one</em>") Renders: <option>Option <em>one</em></option>
func RawTextf ¶
RawTextf creates a new option element with formatted raw text content. Uses text.RawTextf which is not HTML-escaped. Example: option.RawTextf("<em>%s</em>", label) Renders: <option><em>Name</em></option>
func Selected ¶ added in v0.3.0
Selected creates a pre-selected option element with a value and display text. Uses text.Text which HTML-escapes the output. Example: option.Selected("gb", "United Kingdom") Renders: <option value="gb" selected>United Kingdom</option>
func Static ¶
func Static(content string) *element
Static creates a new option element with static text content. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Example: option.Static("None") Renders: <option>None</option>