-2

I've been doing some work on a jQuery script of mine. What I currently have is an image and when clicked it will append an input type text.

$(document).ready(function() {

$('.addParticipant').click(function() {

    $('.addParticipantDiv').append('<p><img src="images/iconminus.jpg" style="width:38px; height:38px;cursor:pointer;position:absolute;margin-top:5px;-moz-border-radius: 4px;border-radius: 4px;" class="removeParticipant"/><input type="text" name="ck_email" class="mailitem" style="width:170px;background:#fff; margin-left:40px"/></p>');

});

$('.removeParticipant').click(function() {

    alert('oi');

});

});

However I've noticed that this do not work since I am trying to call a click event on a element that has been created dynamically with append. What would be the solution to this challenge? The alert or .removeParticipant does not work.

anonamas
  • 243
  • 1
  • 6
  • 15
  • 1
    One possible solution would be to make a search before posting for over thousand duplicates relative to the exact same issue. You use correct terms for search, so no excuse... ;) – A. Wolff Aug 08 '13 at 13:31

1 Answers1

0

You need to use jQuery .on() (it was .live() before, but that's deprecated)

Levi Kovacs
  • 1,159
  • 8
  • 14
  • I tried this $(".removeParticipant").on("click",function(){ alert("The paragraph was clicked."); }); However it did not do a thing. Am I missing something here? – anonamas Aug 08 '13 at 13:36