dom

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendChild

func AppendChild(node *html.Node, child *html.Node)

AppendChild adds a node to the end of the list of children of a specified parent node. If the given child is a reference to an existing node in the document, AppendChild() moves it from its current position to the new position.

func ChildNodes

func ChildNodes(node *html.Node) []*html.Node

ChildNodes returns list of a node's direct children.

func Children

func Children(node *html.Node) []*html.Node

Children returns an HTMLCollection of the direct child elements of Node.

func ClassName

func ClassName(node *html.Node) string

ClassName returns the value of the class attribute of the specified element.

func CloneNode

func CloneNode(src *html.Node) *html.Node

CloneNode returns a deep clone of the node and its children. However, it will be detached from the original's parents and siblings.

func CreateElement

func CreateElement(tagName string) *html.Node

CreateElement creates a new ElementNode with specified tag.

func CreateTextNode

func CreateTextNode(data string) *html.Node

CreateTextNode creates a new Text node.

func DocumentElement

func DocumentElement(doc *html.Node) *html.Node

DocumentElement returns the Element that is the root element of the document. Since we are working with HTML document, the root will be <html> element for HTML documents).

func FirstElementChild

func FirstElementChild(node *html.Node) *html.Node

FirstElementChild returns the object's first child Element, or nil if there are no child elements.

func ForEachNode

func ForEachNode(nodeList []*html.Node, fn func(*html.Node, int))

ForEachNode iterates over a NodeList and runs fn on each node.

func GetAllNodesWithTag

func GetAllNodesWithTag(node *html.Node, tagNames ...string) []*html.Node

GetAllNodesWithTag is wrapper for GetElementsByTagName() which allow to get several tags at once.

func GetAttribute

func GetAttribute(node *html.Node, attrName string) string

GetAttribute returns the value of a specified attribute on the element. If the given attribute does not exist, the value returned will be an empty string.

func GetElementsByTagName

func GetElementsByTagName(doc *html.Node, tagName string) []*html.Node

GetElementsByTagName returns a collection of all elements in the document with the specified tag name, as an array of Node object. The special tag "*" will represents all elements.

func HasAttribute

func HasAttribute(node *html.Node, attrName string) bool

HasAttribute returns a Boolean value indicating whether the specified node has the specified attribute or not.

func ID

func ID(node *html.Node) string

ID returns the value of the id attribute of the specified element.

func IncludeNode

func IncludeNode(nodeList []*html.Node, node *html.Node) bool

IncludeNode determines if node is included inside nodeList.

func InnerHTML

func InnerHTML(node *html.Node) string

InnerHTML returns the HTML content (inner HTML) of an element. The returned HTML value is escaped.

func NextElementSibling

func NextElementSibling(node *html.Node) *html.Node

NextElementSibling returns the Element immediately following the specified one in its parent's children list, or nil if the specified Element is the last one in the list.

func OuterHTML

func OuterHTML(node *html.Node) string

OuterHTML returns an HTML serialization of the element and its descendants. The returned HTML value is escaped.

func PrependChild

func PrependChild(node *html.Node, child *html.Node)

PrependChild works like AppendChild() except it adds a node to the beginning of the list of children of a specified parent node.

func PreviousElementSibling

func PreviousElementSibling(node *html.Node) *html.Node

PreviousElementSibling returns the the Element immediately prior to the specified one in its parent's children list, or null if the specified element is the first one in the list.

func RemoveAttribute

func RemoveAttribute(node *html.Node, attrName string)

RemoveAttribute removes attribute with given name.

func RemoveNodes

func RemoveNodes(nodeList []*html.Node, filterFn func(*html.Node) bool)

RemoveNodes iterates over a NodeList, calls `filterFn` for each node and removes node if function returned `true`. If function is not passed, removes all the nodes in node list.

func ReplaceChild

func ReplaceChild(parent *html.Node, newChild *html.Node, oldChild *html.Node) (*html.Node, *html.Node)

ReplaceChild replaces a child node within the given (parent) node. If the new child is already exist in document, ReplaceChild() will move it from its current position to replace old child. Returns both the new and old child.

func SetAttribute

func SetAttribute(node *html.Node, attrName string, attrValue string)

SetAttribute sets attribute for node. If attribute already exists, it will be replaced.

func SetTextContent

func SetTextContent(node *html.Node, text string)

SetTextContent sets the text content of the specified node.

func TagName

func TagName(node *html.Node) string

TagName returns the tag name of a Node. If it's not ElementNode, return empty string.

func TextContent

func TextContent(node *html.Node) string

TextContent returns the text content of the specified node, and all its descendants.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL