Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
adding HTML element based on random values

is there any way we can add HTML element based on some value for eg, let's say we are unsure of value(i), after some function "i" value is obtained and depending on "i", in different lines value is shown. Something like if i=3,<p>one</p><p>two</p><p>three</p>. if i=5, five

element should be added in HTML structure

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Considering it's not a ReactJS project ( because in React it's used states for this kind of approach ), in vanilla javascript and HTML you have to use element.append(newContent)

// get a value, random or not
// example of random 0~9
const numberOfIncludes = parseInt(Math.random()*10);

// create the element to be included
let newContent = '';
for ( let i=0 ; i<numberOfIncludes ; i+=1) {
    newContent += '<p>'+i+'</p>';
}

// get the DOM to include
const myWrapper = document.querySelector('body');

// include the content at the bottom
myWrapper.append(newContent);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda