0

I'm trying to build the following using createDocumentFragment() and append it to document.body. My usual approach would be to reference an element by it's id. Since there are no 'ids here, how do I build something like this?

<div class="Mh0NNb VcC8Fc" style="visibility:visible;">
    <div class="M6tHv">
        <div class="aGJE1b">Success</div>
        <div class="dnmu6e"></div>
        <div class="x95qze">Close</div>
        <div class="dnmu6e"></div>
    </div>
</div>

frag = document.createDocumentFragment();

n = document.createElement('div')
n.setAttribute('class','Mh0NNb VcC8Fc')
frag.appendChild(n)

n = document.createElement('div')
n.setAttribute('class','M6tHv')
a = frag.getElementsByClassName('Mh0NNb') // This seems to not work
frag.appendChild(a)
Norman
  • 6,159
  • 23
  • 88
  • 141

0 Answers0