get opening tag including attributes - outerHTML without innerHTML

后端 未结 7 1326
花落未央
花落未央 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] + '>'
    
    0 讨论(0)
提交回复
热议问题