Possible Duplicate:
Event binding on dynamically created elements?
I add some links through an if-statement, that looks like this:
if(jQuery.inArray(keywords[i].toLowerCase(), wordFilter) == -1) {
$('p.suggestions').append('<a href="#" class="suggestion">' + keywords[i] + "</a> ");
}
The links are correctly added. I register a click on every link with the suggestion class like this:
$('p.suggestions a').click(function(e) {
e.preventDefault();
t.add($(this).text());
});
It worked fine when I hardcoded a link in my html-file, and the click was registered and t.add() was executed. But when the links are added with the if-statement, it doesn't work anymore. Anyone got a clue how this comes?