Old jquery click handlers still being active after ID change -


i know subject not clear couldn't find better sentence.

i building ajax form. can save form fields db via clicking save button , getting values db edit button. change #id of save button when edit button clicked. button still act save button change it's #id.

here button:

<a class="btn" id="save_post">save post</a> 

when click on edit button change form values , change #id of save post button;

$('#save_post').attr('id','edit_save_post'); 

after all, firebug shows ok, #id changed.

<a class="btn" id="edit_save_post">save post</a> 

but when click on button doesn't run update db, runs again save. how can have browser forgot old #id?

thanks,

you bound handlers using $('...').click(yourfunction); binds them matching elements @ moment.

if adding/changing elements dynamically, use live events: $('...').live('click', yourfunction);

update:

.live() deprecated now; use $(ancestor).on('click', 'selector', yourfunction) instead ancestor being element or selector exists , contains related elements selected selector; mimic .live() you'd use document ancestor.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -