You are binding an event each time you click. While that is uneffective, i am proposing 2 options :
First option
Get the binding out of your function and write it like that :
$('#songList').on("click", 'a', function (e) {
console.log("ID of selected song: "+$(this).attr('id'));
});
This should be placed when #songList
is currently in the DOM. Maybe it is there when the DOM is ready or you are appending it yourself.
Second option
Turn off the event before adding another .on()
:
$(songListDiv).off('click', 'a').on("click", 'a', function (e) {
console.log("ID of selected song: "+$(this).attr('id'));
});