This question has already been answered:
I load the data with the get method and "insert" it in $ .each
$.each(data.dialogs, function(){ var html = ''; html += '<li data-id="'+ this.id +'" class="im_dialogs">'; html += '<a href="#'+ this.id +'">'; html += ' <div class="dialogsEachImg"><img src="/uploads/users/'+ this.avatar +'" alt=""></div>'; html += '<div class="dialogsEachLogin">'+ this.login +'</div>'; html += '<div class="dialogsEachMessage">'+ this.message +'</div>'; html += '</a>'; html += '</li>'; $('.dialogsEach').append(html); });
.dialogsEach
is <ul>
Then, I need to track clicks on these elements (there may be a bunch of them), read the data-id and transfer to the server.
The problem is reading ID, I just can not.
As I understand it, the problem is that due to the fact that I use append , I need to read it differently (most likely).
Tried to find a solution in Google, but the golyak. Get out.
UPD: If I specify a class that is dynamically created, then when clicking instead of the specified URL, favicon.ico loads