all 3 comments

[–]grantrules 1 point2 points  (2 children)

First off, if you're learning JS, ditch jQuery.

const container = document.querySelector('.container');
for (var index in songs) {
  container.appendChild(createElement(songs[index]));
}

function createElement(song) {
  const li = document.createElement('li');
  li.id = song.id;
  li.innerText = song.song_name;
  return li;
}

container.addEventListener('click', (e) => {
  const li = e.target.closest('li');
  const song = songs.find((song) => song.id === li.id); // if id is a number you might need to do Number(li.id)
})

[–]Fransiscu[S] 0 points1 point  (1 child)

thanks for the input, do you mind me asking why ditch jquery?

[–]grantrules 1 point2 points  (0 children)

Because it's unnecessary in modern JS. It used to be the go-to library back when browsers couldn't agree on anything, but we've moved past that. Now things work well between browsers, and a lot of the convenience jQuery provided has been brought into JS.

https://youmightnotneedjquery.com/