jquery - Live handling does not work with event.stopPropagation(); -


i'm using event.stoppropagation(), having problems using .live() handler on parent.

//does not work $("#testlink").live({      click: function(event)      {          alert('testlink');      }  });   //works great!  $("#testlink").click(function() {    alert('testlink');  }); 

i have use .live() because content loaded ajax.

can me problem?


how can use more classes or ids this?

$('#div1', '#div2', '#div3').on('click', 'a.testlink', function(){    alert('testlink');  }); 

how possible?

use on() (as @techfoobar mentioned, live() deprecated in version 1.7 , removed of version 1.9) , event delegation if content dynamically generated:

$('#container').on('click', '#testlink', function(){    alert('testlink');  }); 

where #container element containing dynamically loaded #testlink element (you use document, using container element here reduces search scope , increases efficiency).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -