You can insert new HTML with pure.js

2

I want to use the pure.js framework, to create a post via json.

I found it on the Stack platform in English this topic , which is what I want to do, but there is a problem, I am not able to make the example of the second person who answered below.

Arturo Hernandez;

In your example, your HTML template should look like this:

<ul>
  <li>
    <img src="/img/pappo.gif" />
    <h1>marte</h1>
    <p><a href="#">##                    
asked by anonymous 06.09.2017 / 19:04

1 answer

1

If you have a list of objects it is easier, so you can browse the list and associate the values of each respective object with the html injection you want to do. Incidentally, you can do html injection without any framework.

An example of an object list:

    { 
      listaObj : [
        {
          nome : "Testador",
          idade : 25,
          sexo : "M"
        },{
          nome : "Testadora",
          idade : 22,
          sexo : "F"
        }
     ]
   }

In this way you scroll through the list looking at objects more dynamically only using their attributes and you can do the html injection. Here's an example using the list of objects above.

var divCentral = document.getElementById("central");
for(var i = 0; i < listaObj.length; i++){
  var divNome = document.createElement("div")
  divNome.innerHTML = listaObj[i].nome
  divCentral.appendChild(divNome)
}

In this way the size of the list of your objects is indifferent, the code will always work.

:)

    
06.09.2017 / 20:18