i´m trying to create a dynamically button with a jquery instruction append, but first i remove the content from the container div this all occurs when click an image, so the button created after that event should be repacing the las one, however, the problem is that the button erased still executing its own onlcick event , so i get multiple window open in my browser.
i leave below the code , i hope some body can help to understand whats happening , by the way i don´t know why but the button is created inside a span tag in the DOM ... and then just inside the div container.
<script>
idDelegacion = 0;
function planoClick(id) {
idDelegacion = id;
$.ajax({
type: 'GET',
contentType: "application/json; charset=utf-8",
url: '@Url.Action("partialViewLuminariasDelegacion","Luminaria")',
data: {
"idDelegacion": idDelegacion
},
datatype: "json",
success: function (data) {
$("#luminariasDelegacion").html(data);
$("#nuevaLuminaria").show();
$("#luminariasDelegacion").show();
$("#nuevaLuminaria").empty();
//$("#nuevaLuminaria").live().ready(function () { $("#nuevaLuminaria").children().children("#btnNuevaLuminaria").remove(); });
$("#nuevaLuminaria").append('<input type="button" value="Nueva Luminaria" id="btnNuevaLuminaria" style="position:relative"/>').button().click(function jsAbreOperacionLuminaria() {
url = "../../Luminaria/Create/?idDelegacion=" + idDelegacion
window.open(url);
});
},
error: function () {
alert('error al traer las luminarias de la delegación ' + idDelegacion)
}
});
}
</script>