What I am trying to do:
dynamically build a onclick event attached to an img tag and pass 3 values. The problem is that the onclick is within a loop so the value of the passed values change depending on their position within the loop.
I have managed to get one value passed by attaching it to the img id, but im at a loss as to how to pass the other two
newElement.innerHTML = '<img id="'+ id + '" class="Videoimg" onclick="myFunction(this.id,\"" + VideoTitlePlayer + "\","' + VideodescPlayer + '")" src="' + thumbnail +'"><div id="VideoNames" class="VideoTitle">'+ title +'<br><div class="VideoDescription">' + desc + '</div></div>';
OK so this is the issue
This function is called to build a menu of youtube videos
$.each(playlistVideoItems, function (index, item)
{
displayVideoResult(item.snippet, item.snippet.resourceId.videoId);
});
function displayVideoResult(videoSnippet, VideoPlay)
{ var title = videoSnippet.title;
var desc = videoSnippet.description;
var thumbnail = videoSnippet.thumbnails.default.url;
var id = VideoPlay;
var newElement = document.createElement("div");
newElement.setAttribute("class", "VideoContainerCSS");
// Set the value to what you want
newElement.innerHTML = '<img id="'+ id + '" class="Videoimg" onclick="myFunction(this.id)" src="' + thumbnail +'"><div id="VideoNames" class="VideoTitle">'+ title +'<br><div class="VideoDescription">' + desc + '</div></div>';
document.getElementById("results").appendChild(newElement);
}
I need some way to build into the link the videoID, video Title and Video desc so when the img link is clicked it passes all 3 to a function that runs the youtube api