views:

24

answers:

2

Hi, i create some links on the fly ...

 $('input[name="iplus"]').click(function() {  
    $(ol).append("<a href='#' title='delposition' class='beschr-"+($("#billsumary ol>li").length+1)+"'>l&ouml;schen</a>");  
}); 

now I like to target each created link like $('a[title='delposition']') and assign a click-event like:

$("a[title='delposition']").click(function() {
 alert("Link klicked ...");
});

...but this dont do it? Any suggestions?

A: 

The live() method of JQuery should do the trick:

$("a[title='delposition']").live('click', function() {
 alert("Link klicked ...");
});
Sarfraz
..yes thats it..thanks for the quick answer :)
Don
+1  A: 

You can assign the click handler when you create the element, like this this:

$('input[name="iplus"]').click(function() {  
  $("<a href='#' title='delposition' class='beschr-"+($("#billsumary ol>li").length+1)+"'>l&ouml;schen</a>")
  .click(function() {
    alert("clicked on");
  }).appendTo(ol);  
}); 

This builds the element, adds a click handler, then appends it to the ol object like your original code.

Nick Craver