MCPcopy
hub / github.com/PuerkitoBio/goquery / WrapAllNode

Method WrapAllNode

manipulation.go:470–490  ·  view source on GitHub ↗

WrapAllNode wraps the given node around the first element in the Selection, making all other nodes in the Selection children of the given node. The node is cloned before being inserted into the document. It returns the original set of elements.

(n *html.Node)

Source from the content-addressed store, hash-verified

468//
469// It returns the original set of elements.
470func (s *Selection) WrapAllNode(n *html.Node) *Selection {
471 if s.Size() == 0 {
472 return s
473 }
474
475 wrap := cloneNode(n)
476
477 first := s.Nodes[0]
478 if first.Parent != nil {
479 first.Parent.InsertBefore(wrap, first)
480 first.Parent.RemoveChild(first)
481 }
482
483 for c := getFirstChildEl(wrap); c != nil; c = getFirstChildEl(wrap) {
484 wrap = c
485 }
486
487 newSingleSelection(wrap, s.document).AppendSelection(s)
488
489 return s
490}
491
492// WrapInner wraps an HTML structure, matched by the given selector, around the
493// content of element in the set of matched elements. The matched child is

Callers 1

wrapAllNodesMethod · 0.95

Calls 5

SizeMethod · 0.95
cloneNodeFunction · 0.85
getFirstChildElFunction · 0.85
newSingleSelectionFunction · 0.85
AppendSelectionMethod · 0.80

Tested by

no test coverage detected