Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
how to add innerHTML in another row?

I am trying to add a list of users under the "participants". My current code add the elements next to the work participants.

    showname.innerHTML = `<h4>participants:</h4>` + '<ul>' + users.map(function (user) {
        return '<li>' + user + '</li>';
    }).join('') + '</ul>';

So I like something like this:

participants:

-user1
-user2
-user3

but currently it is:

participants: user1 user2 user3

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There's not much wrong in your code unless you didn't assign selector properly. If you have a div with class container, here is what you should do without changing your code.

const showname = document.querySelector('.container');
const users = ['Solomon', 'Abebe', 'Sara'];
showname.innerHTML = '<h4>participants:</h4>' + '<ul>' + users.map(function (user) {
        return '<li>' + user + '</li>';
}).join('') + '</ul>';

The other option is to create html elements and append them on the existing

const containerBox = document.createElement('div');
containerBox.classList.add = 'container-box';
showname.appendChild(containerBox);
containerBox.innerHTML = '<h4>participants:</h4>' + '<ul>' + users.map(function (user) {
        return '<li>' + user + '</li>';
}).join('') + '</ul>';

As I said, there's not much you should change. I hope this helps.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Why don't you simply add <br> tag at the end of each user record?

showname.innerHTML = '<h4>participants:</h4><br>' + '<ul>' + users.map(function (user) {
    return '<li>' + user + '</li>' + '<br>';
}).join('') + '</ul>';
about 4 years ago · Juan Pablo Isaza Denunciar

0

In JS you can create HTMl Elements by using createElement(tagName). Then you can use innerText or innerHTMl to add text to html to the element. Then you have to append to the parent element.

working example

const ul = document.querySelector('ul');
const ps = ["p1","p2","p3"];
const h4 = document.createElement('h4');

ps.forEach(p => {
  const li = document.createElement('li');
  li.innerHTML = p;
  ul.appendChild(li)
})
<h4>participants:</h4>
<ul></ul>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda