# dom [](https://pkg.go.dev/github.com/JohannesKaufmann/dom) Helper functions for "net/html" that make it easier to interact with `*html.Node`. π [Getting Started](#getting-started) - π [Documentation](#documentation) - π§βπ» [Examples](/examples/) ## Installation ```bash go get -u github.com/JohannesKaufmann/dom ``` > [!NOTE] > This "dom" libary was developed for the needs of the [html-to-markdown](https://github.com/JohannesKaufmann/html-to-markdown) library. > That beeing said, please submit any functions that you need. ## Getting Started ```go package main import ( "fmt" "log" "strings" "github.com/JohannesKaufmann/dom" "golang.org/x/net/html" ) func main() { input := `
` doc, err := html.Parse(strings.NewReader(input)) if err != nil { log.Fatal(err) } // - - - // firstLink := dom.FindFirstNode(doc, func(node *html.Node) bool { return dom.NodeName(node) == "a" }) fmt.Println("href:", dom.GetAttributeOr(firstLink, "href", "")) } ``` ## Node vs Element The naming scheme in this library is: - "Node" means `*html.Node{}` - This means _any_ node in the tree of nodes. - "Element" means `*html.Node{Type: html.ElementNode}` - This means _only_ nodes with the type of `ElementNode`. For example `