class Nokogiri::XML::NodeSet

def wrap(node_or_tags)


#
#
#
#
#
# =>
doc.to_html
doc.css("a").wrap(doc.create_element("div"))
HTML

d
c
b
a

doc = Nokogiri::HTML5(<<~HTML)

having to reparse the wrapper markup for each node.
💡 Note that this is faster than the equivalent call passing a +String+ because it avoids

*Example* with a +Node+ argument

#
#
#
#
#
# =>
doc.to_html
doc.css("a").wrap("
")
HTML

d
c
b
a

doc = Nokogiri::HTML5(<<~HTML)

*Example* with a +String+ argument:

Also see Node#wrap

use by passing a +Node+ instead.
NodeSet. You can avoid this overhead in cases where you know exactly the wrapper you wish to
âš  Note that if a +String+ is passed, the markup will be parsed once per node in the

[Returns] +self+, to support chaining.

An element that is `#dup`ed and used as the wrapper.
- *node* (Nokogiri::XML::Node)
node is used as the wrapper.
associated document is used. If the parsed fragment has multiple roots, the first root
node's parent, if it exists, is used as the context node for parsing; otherwise the
Markup that is parsed, once per member of the NodeSet, and used as the wrapper. Each
- *markup* (String)
[Parameters]

Wrap each member of this NodeSet with the node parsed from +markup+ or a dup of the +node+.

wrap(node) -> self
wrap(markup) -> self
:call-seq:
def wrap(node_or_tags)
  map { |node| node.wrap(node_or_tags) }
  self
end