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

169
Vistas
How to add List Items DOM from a JSON string in JS/Jquery
data = [
{ "id" : "1", 
    "prepare" : "Hello welcome to xyz portal || 1. Please login to system || 2. Open dashboard || Verify your details and confirm."
    },
{ "id" : "2", 
    "prepare" : "Hello welcome to portal || a. Please click on link || b. Open the details list items || Check and confirm the details."
    }
]

I need to prepare HTML DOM from this JSON, like paragraph in P tag and numbered or alphabet items in list items. I am trying like below putting everything in P tag including number and alphabets.

But i need those number/alphabets to be placed inside ol/ul/li tags and type should display from list-style-type in css, please help me how can we do that..

var htmlArray = [];
for (i = 0 ; i< data.length ; i++){
    var dataString= data[i].prepare.split("||");
    for(j = 0 ; j<dataString.length; j++){
        var htmlString = "<p>"+dataString[i]+"</p>";
        htmlArray.push(htmlString);
    }
}

htmlDOM = "<div>"+htmlArray.join('')+"</div>";
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do following:

<ul id="jsonDiv"></ul>
<script>
  data = [
    {
      id: "1",
      prepare:
        "Hello welcome to xyz portal || 1. Please login to system || 2. Open dashboard || Verify your details and confirm.",
    },
    {
      id: "2",
      prepare:
        "Hello welcome to portal || a. Please click on link || b. Open the details list items || Check and confirm the details.",
    },
  ];
  var htmlArray = [];
  for (i = 0; i < data.length; i++) {
    var dataString = data[i].prepare.split("||");
    for (j = 0; j < dataString.length; j++) {
      var htmlString = "<p>" + dataString[j] + "</p>";
      htmlArray.push(htmlString);
    }
  }

  htmlDOM = "<div>" + htmlArray.join("") + "</div>";

  var targetDiv = document.getElementById('jsonDiv');
  targetDiv.innerHTML = htmlDOM;
</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can do something like this

const data = [
{ "id" : "1", 
    "prepare" : "Hello welcome to xyz portal || 1. Please login to system || 2. Open dashboard || Verify your details and confirm."
    },
{ "id" : "2", 
    "prepare" : "Hello welcome to portal || a. Please click on link || b. Open the details list items || Check and confirm the details."
    }
]

const container = document.getElementById('container')

const formatHtml = ([p,...li]) => `<p>${p}</p><ul>${li.map(l => `<li>${l}</li>`).join('')}</ul>`

const html = data.map(d => `<div>${formatHtml(d.prepare.split(' || '))}</div>`).join('')

container.innerHTML = html
<div id="container"></div>

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