Skip to content

Commit 85ccf1a

Browse files
committed
Make Node#{pre,ap}pend_to return the appended node
This commit introduces a slight incompatibility, but hopefully it's a worthy one. The rationale is that I often tend to write code like: `DOM { div }.append_to(other_node)` to construct a DOM tree and append it in one go. When I try to capture the tree, I can't - I think it makes no sense to return a parent. Regarding other cases where this is done this way, I would note jQuery even if some people may say it's an unpopular comparison, but I want this library to give jQuery users a familiar interface. Nokogiri has no say about this - it doesn't have {pre,ap}pend_to. Do note, that it makes no change to << and >> which should return a parent node.
1 parent 91ddf83 commit 85ccf1a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

opal/browser/dom/node.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def add_previous_sibling(node = nil, &block)
165165
# @param node [Node] the node to append to
166166
def append_to(node)
167167
node << self
168+
self
168169
end
169170

170171
# Get an array of ancestors.
@@ -396,6 +397,7 @@ def path
396397
# @param node [Node] the node to prepend to
397398
def prepend_to(node)
398399
node >> self
400+
self
399401
end
400402

401403
# @!attribute previous

0 commit comments

Comments
 (0)