I try to replace an html element by a new html element which has been computed and returned by twig. But the replaceWith function understands it as a string and not an html element
function replaceItem(item, html) {
item?.replaceWith(html);
}
Before replaceItem After replaceItem
Have try this :
function replaceItem(item, html) {
newItem = create.element(html);
item?.replaceWith(newItem);
}
function replaceItem(item, html) {
item?.replaceWith(html).html();
}
CodePudding user response:
Since item
is a DOM element, you're calling the DOM method, not the jQuery method. The DOM version doesn't interpret HTML, it treats it as literal text.
So use the jQuery method:
function replaceItem(item, html) {
if (item) {
$(item).replaceWith(html);
}
}