Skip to content

Instantly share code, notes, and snippets.

@aautar
Created August 13, 2018 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aautar/121151a448bfbf0276c3ab957ecfeb6c to your computer and use it in GitHub Desktop.
Save aautar/121151a448bfbf0276c3ab957ecfeb6c to your computer and use it in GitHub Desktop.
jQuery version of insertAdjacentElement (b/c jsdom doesn't doesn't implement)
Element.prototype.insertAdjacentElement = function(position, elem) {
let _this = this;
switch (position.toLowerCase()) {
case 'beforebegin':
$(_this).before($(elem));
break;
case 'afterbegin':
$(_this).prepend($(elem));
break;
case 'beforeend':
$(_this).append($(elem));
break;
case 'afterend':
$(_this).after($(elem));
break;
}
return elem;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment