Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insertAdjacentHTML is not a function

So Im working with electron and in my file "ipcRendererEvent.js" I wrote the following code:

function loadImages (images) {
  const imagesList = document.querySelectorAll('ul.list-group')

  for (let i = 0, length1 = images.length; i < length1; i++) {
    const node = `<li class="list-group-item">
                    <img class="media-object pull-left" src="${images[i].src}" height="32">
                    <div class="media-body">
                      <strong>${images[i].filename}</strong>
                      <p>${images[i].size}</p>
                    </div>
                  </li>`
    imagesList.insertAdjacentHTML('beforeend', node)
  }
}

And this is the error:

Uncaught TypeError: imagesList.insertAdjacentHTML is not a function
    at loadImages (ipcRendererEvents.js:22)
    at EventEmitter._electron.ipcRenderer.on (ipcRendererEvents.js:58)
    at EventEmitter.emit (events.js:182)
like image 897
Agoss Avatar asked Jan 22 '19 00:01

Agoss


People also ask

Is insertadjacementhtml a function at <anonymous>?

javascript - insertAdjacementHTML is not a function at <anonymous> - Stack Overflow I am trying to place a button after an already existing button on another website. I'm trying to test it out in Chrome console, but can't figure it out.

Does element insertadjacenthtml API throw error in chrome 55?

Element.insertAdjacentHTML() API throws error in chrome 55.0.2883.87 Ask Question Asked4 years, 8 months ago Active1 year, 6 months ago Viewed14k times 12 I found the explaination about the API here, which tells me the second parameter is a string. It's perform normal in firefox.

How to insert insert adjacent element in HTML?

insertAdjacentElement(position, element) The second parameter should be an element and not html text. E.g. var newDiv = document.createElement('div'); newDiv.style.backgroundColor = 'white'; parentElement.insertAdjacentElement('beforeend',newDiv);


2 Answers

querySelectorAll returns a NodeList. You could use querySelector instead to get the first matching element in the document or you can call insertAdjacentHtml on an individual element in the list (e.g.: imagesList[0].insertAdjacentHTML).

like image 191
jspcal Avatar answered Sep 24 '22 04:09

jspcal


The correct notation is insertAdjacentHTML. You have a small typo :)

like image 26
Meindert Stijfhals Avatar answered Sep 25 '22 04:09

Meindert Stijfhals