Agregué varias <option> para #inputPanel , luego intenté configurar <select>
for (i = 0 ;i < data.length;i++){ $('#inputPanel').append(`<option>${data[i]['name']}</option>`); } $('#inputPanel').after("</select>"); $('#inputPanel').before("<select>"); console.log($('#inputPanel').html()); // there is not select??? La etiqueta de select no se agrega a DOM .
¿Cómo puedo hacer esto?
Una <option> no tiene sentido si no es un hijo de una <select> . Cree el <select> primero.
const data = [{ name: 'a' }, { name: 'b' }]; const select = $('<select>').appendTo('#inputPanel'); for (const { name } of data) { $('<option>') .text(name) // .text is safer than direct interpolation .appendTo(select); } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="inputPanel"></div>