javascript - usage of jquery .live() to work with both present and future DOM -


i've jquery code as

$('#tarea').click(function() {      // stuffs }); 

this works fine button #tarea loaded along script. if button #tarea had been loaded using ajax in future, above code doesn't work.

now changed code to

$('#tarea').live('click', function() {      // stuffs }); 

this time, button #tarea if loaded along script doesn't work. script works button if generated using ajax.

how write script in both cases, works??

.live() works in both cases without doing additional have done. check other problems in code might preventing happening.

important: 1 thing check make sure .live() event being bound , doesn't rely on other event happening. might post important parts of javascript file. declare .live() events globally.

i this:

// mean global because outside document.ready $("#test").live("click", function() {     // stuff });  $(function() {     // stuff when document ready }); 

if want prove said above, need put button , .live() javascript code in new html file.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -