Skip to content

Imperative DOM Manipulation #32

@codeCraft-Ritik

Description

@codeCraft-Ritik

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions