I'm using the YouTube API to populate a list of cards to my app using an each function. These cards are placed into a variable, then appended to a playlist container.
Within the individual cards is a switch to "favorite" a video. The switch, along with rest of the card is populated dynamically, so I'm trying to use the "on" "change", instead of ".change" "function". From what I've ready the on method is what you use to manipulate dynamic elements.
The challenge I'm running into is that I cannot seem to get the correct state of the switch(checkbox), and I'm always returning the first if statement no matter what I'm doing. Can anyone spot what I'm doing wrong here? The plan is to push to firebase if a user clicks to "favorite" a video, but I cannot get this function working. Thanks in advance! :D
$(document).on("change", ".switch", function () {
if (this.checked) {
console.log("Checked");
} else {
console.log("NOT Checked");
}
});