B
B
BoriHagen2020-04-25 13:41:26
JavaScript
BoriHagen, 2020-04-25 13:41:26

How to insert into HTML document with JS variables?

There is this code:

var item;
            function addItemInOrder (button){
              var item = button.closest(".main__categoties-wrapper__categorie-item");
              var itemImg = item.querySelector("img");
              var itemName = item.querySelector(".main__categoties-wrapper__categorie-item__tittle");
              var itemVendorCode = item.querySelector(".vendor-code");
              var itemPrice = item.querySelector(".item-price").innerText;
              var itemResult = `<div class='order-item'><div class='order-item__data-left'><div class='order-item__data-left__img'>${itemImg}</div><div class='order-item__data-left__item-data'>${itemName}${itemVendorCode}</div></div><div class='order-item__data-right'><div class='order-item__data-right__delete-item'><button class='delete-item'>Удалить</button></div><div class='order-item__data-right__item-price'><h3>Цена: ${itemPrice}р</h3></div></div>`
document.querySelector(".main__order-items-wrapper").innerHTML(itemResult);
}


Here I get blocks with product data displayed using php and write each block to a variable. Now you need to somehow insert these variables wrapped in other html blocks in another part of the document. But the console throws an error document.querySelector(...).innerHTML is not a function

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tigran Abrahamyan, 2020-04-25
@BoriHagen

not written correctly

document.querySelector(".main__order-items-wrapper").innerHTML(itemResult);

do so
document.querySelector(".main__order-items-wrapper").innerHTML = itemResult;

T
tempick, 2020-04-25
@tempick

document.querySelector(...).innerHTML = {your variable here}
innerHTML is not a function, that's what the interpreter says. It is necessary not to put brackets, but the sign "="

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question