From 7e0318043ea3a71963624f6d32bf1b3e59094134 Mon Sep 17 00:00:00 2001 From: Matt Mombrea Date: Wed, 13 Apr 2016 14:53:59 -0400 Subject: [PATCH] add option containerSelector to specify which element to clone into --- src/headhesive.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/headhesive.js b/src/headhesive.js index 8c717fc..282f0e6 100644 --- a/src/headhesive.js +++ b/src/headhesive.js @@ -30,6 +30,7 @@ this.options = { offset: 300, offsetSide: 'top', + containerSelector: 'body', classes: { clone: 'headhesive', stick: 'headhesive--stick', @@ -68,7 +69,7 @@ // Clone element this.clonedElem = this.elem.cloneNode(true); this.clonedElem.className += ' ' + this.options.classes.clone; - document.body.insertBefore(this.clonedElem, document.body.firstChild); + document.querySelector(this.options.containerSelector).insertBefore(this.clonedElem, document.querySelector(this.options.containerSelector).firstChild); // Determin offset value if (typeof this.options.offset === 'number') {