javascript - Execute a function on currently non-existing ID -


i have button on page, calls jquery function this:

$('[id^=edit]').one('click',function (){     id = $(this).attr('id')     changedid = id.replace('edit', '') // cut off word 'edit'     oldvalue = $('#' + changedid).text()     $('#' + changedid).html("<input class='myinput' type='text' value='" + oldvalue +"'/>");     $(this).addclass('success');     $(this).attr('id', changedid+'button');     $(this).text("save it") }); 

basically, click creates input element in paragraph, , adds class button, , changes it's id.

i write second function executed when button new id clicked. example:

$('[id$=button]').click(function(){     alert("it works");  }); 

is possible? new function trigger ajax call django app, that's irrelevant.

if want event delegated not yet existing element, use on :

 $(document.body).on('click', '[id$=button]', function(){ 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -