0

I have the following code:

sortableList = $("#itemlist");
$(sortableList).click(function(){
   console.log($(this).children().attr('id'));
});

The list contains elements that are direct descendants with ids from id_0 to id_9. I want to get the specific id of the element I am clicking. By running above the above code, the function logs only the id of the first child, regardless of the child I click on.

Salman A
  • 229,425
  • 77
  • 398
  • 489
Bogdan
  • 188
  • 3
  • 14

1 Answers1

0

Assuming #itemlist has div as its children:

$("#itemlist").on("click", "div", function() {
    console.log(this.id);
});
Salman A
  • 229,425
  • 77
  • 398
  • 489
  • I forgot to mention that the children are divs, but it worked once I replaced li with div. Thank you! – Bogdan Oct 09 '18 at 11:17