Improve the replace function to iterate over childnodes, allowing it to handle multiple nodes

This commit is contained in:
William Karsten 2022-06-07 11:52:16 -05:00
parent d8fc4876e6
commit 1ad1a4d6e2
1 changed files with 3 additions and 2 deletions

View File

@ -515,12 +515,13 @@ const onPageLoad = (callback) => {
const replace = (oldElement, newHTMLString) => {
const placeHolder = document.createElement('div');
placeHolder.insertAdjacentHTML('afterBegin', newHTMLString);
const newElement = placeHolder.firstElementChild;
oldElement.replaceWith(newElement);
const newElements = placeHolder.childNodes.values();
oldElement.replaceWith(...newElements);
}
onPageLoad(() => {
// Global Functions
on('click', '.markdown_help_label', (event) => {
parentSelector(event.target, '.markdown_help_toggler').querySelector('.markdown_help').classList.toggle('display-block');
});