javascript - jquery event not working after append -


http://jsfiddle.net/ysnht/2/

jquery event on not working after append. need value of textarea after click save button.

$('.span8')     .on('click',             '.btn',             function() {         var input = $("#textarea").val();         alert(input);     });  $('body').on('click','#createnote',function() {                $('.span8').empty();                 $('.span8').append('<button type="button" class="btn" style="float: right; margin-right: 8px;background-color:#dddddd;font-family:roboto slab;color: black" id="save" data-loading-text="saving...">save</button><div class="hero-unit"><input type="text" style="width: 100%" id="title" placeholder="title"/>'+                  '<textarea contenteditable="true" id="textarea" class="textarea" placeholder="enter text ..."style="width: 100%;">dd</textarea></div>');              }); 

html:

<div class="span8"></div> 

since #save dynamically created, use following handler:

$(document).on('click', '#save' ,function() {     //do stuff }); 

updated fiddle: http://jsfiddle.net/tymejv/ysnht/3/

you should make "click" button handler this, or else not fire on newly created #click buttons.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -