dom

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package dom defines Growse's browser-owned document model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Root *Node
	// contains filtered or unexported fields
}

Document owns a DOM tree and its node indexes.

func NewDocument

func NewDocument() *Document

NewDocument creates an empty document with a document root node.

func (*Document) AppendChild

func (d *Document) AppendChild(parent, child *Node) error

AppendChild attaches child beneath parent.

func (*Document) CreateElement

func (d *Document) CreateElement(tagName string, attributes map[string]string) *Node

CreateElement creates an unattached element owned by the document.

func (*Document) CreateText

func (d *Document) CreateText(text string) *Node

CreateText creates an unattached text node owned by the document.

func (*Document) ElementCount

func (d *Document) ElementCount() int

ElementCount returns the number of element nodes.

func (*Document) GetElementByID

func (d *Document) GetElementByID(id string) (*Node, bool)

GetElementByID returns the first element with the given id attribute.

func (*Document) IsConnected

func (d *Document) IsConnected(node *Node) bool

IsConnected はノードがDocumentのルートツリーに接続されているかを返す。

func (*Document) NodeByID

func (d *Document) NodeByID(id NodeID) (*Node, bool)

NodeByID returns the node with the internal document-scoped identifier.

func (*Document) NodeCount

func (d *Document) NodeCount() int

NodeCount returns the number of nodes, including the document root.

func (*Document) QuerySelector

func (d *Document) QuerySelector(value string) (*Node, bool)

QuerySelector は対応する単純セレクターに最初に一致する要素を返す。

func (*Document) Remove

func (d *Document) Remove(id NodeID) ([]NodeID, bool)

Remove は接続済み要素とその子孫をDocumentから削除し、削除したNodeIDを返す。

func (*Document) RemoveAttribute added in v0.8.0

func (d *Document) RemoveAttribute(id NodeID, name string) bool

RemoveAttribute removes an element attribute and reports whether it existed.

func (*Document) SetAttribute

func (d *Document) SetAttribute(id NodeID, name, value string) bool

SetAttribute は要素の属性を設定し、値が変化した場合にtrueを返す。

func (*Document) SetTextContent

func (d *Document) SetTextContent(id NodeID, value string) bool

SetTextContent は指定したノードの子を1つのテキストノードへ置き換える。

func (*Document) Title

func (d *Document) Title() string

Title returns the normalized text of the first title element.

type Node

type Node struct {
	ID NodeID

	Type NodeType

	TagName string
	Text    string

	Attributes map[string]string

	// ControlValue and ControlChecked hold browser-owned live form state. The
	// corresponding HTML attributes remain the reset defaults.
	ControlValue        string
	ControlValueDirty   bool
	ControlChecked      bool
	ControlCheckedDirty bool

	Parent   *Node
	Children []*Node
	// contains filtered or unexported fields
}

Node is one item in a Growse DOM tree.

func (*Node) Attribute

func (n *Node) Attribute(name string) (string, bool)

Attribute returns an attribute value from an element node.

func (*Node) TextContent

func (n *Node) TextContent() string

TextContent returns the concatenated text of the node and its descendants.

type NodeID

type NodeID uint64

NodeID uniquely identifies a node within one document.

type NodeType

type NodeType uint8

NodeType describes the role of a DOM node.

const (
	NodeDocument NodeType = iota
	NodeElement
	NodeText
)

Jump to

Keyboard shortcuts

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