I have the following HTML file:
<div class="tituloD">
</div>
<div class="subtituloD">
</div>
<div class="puntosD">
</div>
I have this JQuery javascript:
// Esta funcion recoge el json data de puntos importantes y lo imprime en pantalla
function resultsPuntos(data) {
//Si el punto no se ha creado antes, se crea la estructura
if(puntosCreados == "No"){
$("div.puntosD").append("Puntos importantes: ");
$.each(data,function(index,value) {
$("div.puntosD").append('<input type=\"checkbox\" name="'+data[index].id+'" value="'+data[index].nombre+'"> '+data[index].nombre);
});
puntosCreados = "Si";
}
else{
//Vaciar estructura
$("#checkbox").replaceWith('');
//Crear estructura de nuevo
$.each(data,function(index,value) {
$("div.puntosD").append('<input type=\"checkbox\" name="'+data[index].id+'" value="'+data[index].nombre+'"> '+data[index].nombre);
});
}
}
I am trying to display a checkbox with the options comming from a database. For that I detect if it’s the first time it’s being created (if(puntosCreados == "No")), if so I write the checkbox structure. If it is not, I try emptying the checkbox structure first ($("#checkbox").replaceWith('');), however, this is not working. How can I do it?
Do you have any checkbox with the ID ‘checkbox’? I think what you mean is: