Skip to content
Advertisement

Newly created div goes to the bottom of the (Ii) list instead in to the selected (li) element?

I will go straight to the issue first concept: I want a div to be created once a user press an icon in a certain area of the html. my most achieving is that the div get created but I want the creation to be index specific instead it goes to the bottom of the Li list which has some other items also I was able to show it inside the li element as well but it doesn’t sere my purpose I want the div to appear right under the li element that has the icon that has been just clicked matching this patter

// if first icon clicked the UI must look like following Ul LI Div Are you sure ??? LI LI UL

any idea ? thanks for help.

JavaScript
JavaScript

Advertisement

Answer

You could achieve your goal through CSS, so i added to your original divs a display style as a flexbox by using style attribute style="display:flex;" and set the message div to margin-left with 1rem, using style="margin-left:1rem;" so you can have your message in the same line beside your icons with 1rem gap.

Try the snippet, best of luck =)

EDIT : As per your request, appended the message to the <li> and added display:inline; to the div to keep showing in the same line.

Also added a console log check for the first <li>

JavaScript
JavaScript
Advertisement