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
  • 262,204
  • 82
  • 430
  • 521
Bogdan
  • 379
  • 2
  • 5
  • 19

1 Answers1

0

Assuming #itemlist has div as its children:

$("#itemlist").on("click", "div", function() {
    console.log(this.id);
});
Salman A
  • 262,204
  • 82
  • 430
  • 521
  • 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