// Selects the container element using jQuery
const container = $('.container');
// Function to create a specified number of div elements
function createElement(num) {
// Loop to create `num` number of div elements
for (let i = 0; i < num; i++) {
// Create a new div element
const div = document.createElement('div');
// Add classes to the div element for styling
div.classList.add('p-5', 'bg-warning', 'm-3');
// Set the inner HTML of the div element
div.innerHTML = `<p>${i + 1}. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus, aliquam!</p>`;
// Append the div element to the container
container.append(div);
// Log the created div element to the console
console.log(div);
}
}
// Uncomment the following line to create 40 div elements
// createElement(40);
Do your career a big favor. Join DEV. (The website you're on right now)
It takes one minute, it's free, and is worth it for your career.
Community matters
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)