DEV Community

_Khojiakbar_
_Khojiakbar_

Posted on

1

Dynamic Element Creation

// 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);

Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →