diff --git a/src/svg.js b/src/svg.js index faec271..96e0466 100644 --- a/src/svg.js +++ b/src/svg.js @@ -1642,6 +1642,20 @@ function arrayFirstValue(arr) { el.paper = this.paper; return this; }; + /*\ + * Element.appendTo + [ method ] + ** + * Appends the current element to the given one + ** + - el (Element) parent element to append to + = (Element) the child element + \*/ + elproto.appendTo = function (el) { + el = wrap(el); + el.append(this); + return this; + }; /*\ * Element.prepend [ method ] @@ -1657,6 +1671,20 @@ function arrayFirstValue(arr) { el.paper = this.paper; return this; }; + /*\ + * Element.prependTo + [ method ] + ** + * Prepends the current element to the given one + ** + - el (Element) parent element to prepend to + = (Element) the child element + \*/ + elproto.prependTo = function (el) { + el = wrap(el); + el.prepend(this); + return this; + }; /*\ * Element.before [ method ] diff --git a/test/element.js b/test/element.js index 2fc290b..f7ccc9a 100644 --- a/test/element.js +++ b/test/element.js @@ -51,6 +51,13 @@ describe("Element methods", function () { expect(rect2.node.parentNode).to.be(s.node); expect(result).to.be(s); }); + it("Element.appendTo", function() { + var rect = s.rect(10, 20, 30, 40); + var result = rect.appendTo(s); + expect(rect.node.parentNode).to.be(s.node); + expect(s.node.lastChild).to.be(rect.node); + expect(result).to.be(rect); + }); it("Element.after", function() { var circle = s.circle(10, 20, 30); var rect = s.rect(10, 20, 30, 40); @@ -70,6 +77,18 @@ describe("Element methods", function () { expect(group.node.firstChild).to.be(circle.node); expect(result).to.be(group); }); + it("Element.prependTo", function() { + var rect = s.rect(10, 20, 30, 40); + var circle = s.circle(10, 20, 30); + var group = s.group(); + s.append(group); + var result = rect.prependTo(group); + expect(group.node.firstChild).to.be(rect.node); + expect(result).to.be(rect); + result = circle.prependTo(group); + expect(group.node.firstChild).to.be(circle.node); + expect(result).to.be(circle); + }); it("Element.insertAfter", function() { var circle = s.circle(10, 20, 30); var rect = s.rect(10, 20, 30, 40);