0
I made two inputs date, and when I click on "generate" it shows on the console the product that has these dates, but it is a variable, how do I turn a class and play in html? there every time I call the class it appears, ex.:
<h2 class="produto-1"></h2>
Then he’d show up.
Obs.: it takes the product from an api that I made.
Code:
<body>
<input type="date" id="inicio">
<input type="date" id="fim">
<button onclick="PostData();">GERAR</button>
<!-- -->
<script>
function PostData() {
var inicio,fim;
inicio = document.getElementById('inicio').value;
fim = document.getElementById('fim').value;
fetch('http://localhost/api', {
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body: `inicio=${inicio}&fim=${fim}`
}).then(response => response.json().then(data => ({
data: data,
status: response.status
})
).then(res => {
var insere = (res.data.dados.nome);
console.log(insere);
})
)
}
</script>
</body>