Event binding with jquery live() function -
first here code:
html:
<div id="foreground"> <button type="button" id="go">start</button> </div> <div id="background"> <p>you on background</p> </div>
js:
$(function () { $("#go").click(function (e) { var $q = $(this); var $vazy = $('<button type="button" id="vazy"> vazy </button>'); var $loc = $('<input type="text" id="placename" placeholder="location"/>'); $vazy.insertafter($q); $loc.insertafter($q); $q.hide(); e.stoppropagation(); }); $("#vazy").live("click", function () { alert('k'); //$("#foreground").hide(); //$("#background").show(); }); });
css:
#background { display: none; }
the problem @ line 15 button id #vazy
seems not respond click event live binding. missing something?
thanks response :)
try this
$("body").on("click","#vazy" function () { alert('k'); //$("#foreground").hide(); //$("#background").show(); });
Comments
Post a Comment