Reputation: 193
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ö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?
Upvotes: 1
Views: 4379
Reputation: 630409
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ö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.
Upvotes: 1