get opening tag including attributes - outerHTML without innerHTML

后端 未结 7 1339
花落未央
花落未央 2020-12-10 03:22

I would like to retrieve a certain tag element with its attributes from the DOM. For example, from


  link text
         


        
7条回答
  •  遥遥无期
    2020-12-10 03:50

    Here's a solution I've used:

    const wrap = document.createElement('div')
    wrap.appendChild(target.cloneNode(true))
    const openingTag = wrap.innerHTML.split('>')[0] + '>'
    

提交回复
热议问题