
ショコラ
JavaScript htmlからエレメントを作成するには?
divでとりあえずのエレメントを作成して、そこから取得する感じです。

もっさん先輩
ライブワイヤーで動的にコンポーネントを作成する場面で使いました。
function createElementFromHtml(html)
{
const el = document.createElement('div')
el.innerHTML = html
return el.firstElementChild
}
Livewire.on('createComponent',(html,target='body') => {
const el = document.createElement('div')
el.innerHTML = html
document.querySelector(target).appendChild(el.firstElementChild)
window.livewire.rescan()
})
以上