E-CommerceWebsite icon indicating copy to clipboard operation
E-CommerceWebsite copied to clipboard

Imperative DOM Manipulation

Open codeCraft-Ritik opened this issue 10 months ago • 0 comments

Description:

The project builds the UI by creating every element one by one using document.createElement. This is difficult to read and makes the HTML structure hard to visualize in the script.

(content.js) - Improved Code:

function dynamicClothingSection(ob) {
  const boxDiv = document.createElement("div");
  boxDiv.id = "box";
  boxDiv.innerHTML = `
    <a href="/contentDetails.html?${ob.id}">
      <img src="${ob.preview}" />
      <div id="details">
        <h3>${ob.name}</h3>
        <h4>${ob.brand}</h4>
        <h2>rs ${ob.price}</h2>
      </div>
    </a>
  `;
  return boxDiv;
}

codeCraft-Ritik avatar Jan 25 '26 08:01 codeCraft-Ritik