0

In my project I'm trying to create, with DOM and JavaScript, a loop to create multiple elements, like this example:

for (i = 0; i < response.click.length; i++) 
{
    var divClick = createElement('div', 'divClick', 'divClk');
    divClick.setAttribute('style','top: '+response.click[i].ypos+';');
    divClick.setAttribute('style','left: '+response.click[i].xpos+';');
    divLogin.appendChild(divClick);
}

In practice I need to append at one main div a series of divs (little blue square - divClick) positioned using value parsing from ypos and xpos, but with this code the result is just one square positioned at 0,0 coordinates.

1 Answer 1

2

Set

position: relative;

on your container div and

position: absolute;

on your child divs.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.