Why does not this work?
I have a variable with a structure html
that when I click on a button I print it on a label p
and then the button that is in that variable add a function click
but doing this does not work .
The same happens when I do it with ajax
that for example if I do the same with ajax I have to add again the script
in the ajax so that I can to operate the funtion, to what is this due?
NOTE: css styles if taken by the variable with the content html
but not the script
Here is an example of what I'm trying to do
$(document).ready(function(){
var contenido='
<div>
<button id="pinchar2"> pinchar</button>
</div>
';
$('#pinchar').click(function() {
alert("pinchado")
$('p').html(contenido);
});
//luego al tratar de agregar la misma funcion a la variable me falla
$("#pinchar2").click(function(){
alert("pinchado")
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div>
<button id="pinchar">check</button>
</div>
<p></p>