diff --git a/lib/core/GraphicsFactory.js b/lib/core/GraphicsFactory.js index 5875570dd..3b8b9dbab 100644 --- a/lib/core/GraphicsFactory.js +++ b/lib/core/GraphicsFactory.js @@ -222,5 +222,7 @@ GraphicsFactory.prototype.remove = function(element) { // helpers ////////////////////// function prependTo(newNode, parentNode, siblingNode) { - parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild); + // must ensure second argument is node or _null_ + // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore + parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild || null); } diff --git a/lib/features/overlays/Overlays.js b/lib/features/overlays/Overlays.js index 551b595ff..3cb923fa9 100644 --- a/lib/features/overlays/Overlays.js +++ b/lib/features/overlays/Overlays.js @@ -617,9 +617,14 @@ Overlays.prototype._init = function() { // helpers ///////////////////////////// -function createRoot(parent) { - var root = domify('
'); - parent.insertBefore(root, parent.firstChild); +function createRoot(parentNode) { + var root = domify( + '
' + ); + + // must ensure second argument is node or _null_ + // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore + parentNode.insertBefore(root, parentNode.firstChild || null); return root; } diff --git a/lib/features/tooltips/Tooltips.js b/lib/features/tooltips/Tooltips.js index 08f2f9b67..aab780a52 100644 --- a/lib/features/tooltips/Tooltips.js +++ b/lib/features/tooltips/Tooltips.js @@ -18,9 +18,15 @@ import Ids from '../../util/IdGenerator'; var ids = new Ids('tt'); -function createRoot(parent) { - var root = domify('
'); - parent.insertBefore(root, parent.firstChild); +function createRoot(parentNode) { + var root = domify( + '
' + ); + + // must ensure second argument is node or _null_ + // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore + parentNode.insertBefore(root, parentNode.firstChild || null); + return root; }