Untitled

 avatar
user_4456378597
plain_text
2 years ago
1.1 kB
60
Indexable
Never
const productsContainer = document.getElementById("details");

const urlParams = new URLSearchParams(window.location.search);
const productId = urlParams.get("id");

const product = products.find((product) => product.id == productId);
// console.log(product);

function createProducts (avatar, name, price) {
    const productArticle = document.createElement("article");
    const imgEl = document.createElement("img");
    const nameEl = document.createElement("div");
    const priceEl = document.createElement("div");
    
    nameEl.textContent = name;
    imgEl.src = avatar;
    priceEl.textContent = price;

    nameEl.classList.add("nameProduct");
    
    productArticle.appendChild(imgEl);
    productArticle.appendChild(nameEl);
    productArticle.appendChild(priceEl);
    productsContainer.appendChild(productArticle);
    return productArticle;
    }
    
    const {avatar, product_name, product_price} = product;

    const productEl = createProducts(avatar,product_name, product_price);

    productsContainer.appendChild(productEl);
    // console.log(productEl);