javascript - Returning id from Ajax generated DOM elements -


i know there duplicate (jquery: how id of dynamically generated element?) tried solution , couldn't fix problem.

an ajax/jquery query has returned table when inspected returns formed table:

<table border="1"> <tbody> <tr><td>example</td><td class="del" id="1">delete</td></tr> <tr><td>example2</td><td class="del" id="2">delete</td></tr> </tbody> </table> 

the jquery code is:

$('.del').click(function(){         var id = $(this).attr("id");         alert(id);     }); 

if put table directly in html works fine when it generated ajax doesn't generate alert (and chrome doesn't return error).

nb appologise in advance if stupid misnamed id have been trying figure out 3/4 hour , stuck!

edit:

the ajax call is:

$.ajax({type : 'post', url : 'response.php'}).done(function(response){         $('#result').html(response);     }); 

rewrite javascript follows

$(document).on("click", ".del", function(){  var id = $(this).attr("id"); alert(id);  });        // jquery 1.7+ 

please refer following article detail http://api.jquery.com/on/


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -