Possible Duplicate:
jquery click doesnt work on ajax generated content
The issue is that I need to perform a JQuery on click function to an <a> tag created from an Ajax get. I can’t seem to find an answer that works for me.
$("#get_button").click(function (e) {
$.ajax({
type: 'GET',
url: 'http://someurl.com/apikey=1234124124',
dataType: 'jsonp',
success: function (data) {
newRow = "<a id='some_id'>test</a>";
$("#table_id").append(newRow);
}
});
});
$('#some_id').click(function (event) {
event.preventDefault();
alert('this will pop up if it worked');
});
Edit for clarification: In my code there are multiple rows added with the id of some_id, I forgot to show that.
you really need to research these types of questions before asking , if you are using newer jquery (i think 1.6 and above ) it is :
older versions use
.live()instead of.on()For the edit in your question – DO NOT have multiple elements with the same id , give them the same class , you can dynamically create ids and add something to each one if you want , like #some_id0 #some_id1 ect…