I'm trying to create a variable in my Javascript that uses the value assigned on data-start-time.
Here is my html:
<li data-pile="1" id="kQKhpVWBjoQ" data-start-time="20" class="md-trigger md-setperspective">
</li>
Here is my JS:
function playVideo(videoId, cb) {
if(videoId) {
myModal.find('.md-video').append($videoDiv);
myModal.addClass('md-show');
setTimeout(function () {
console.log('#### id', videoId);
var startTime = videoId.getAttribute('data-start-time');
player.loadVideoById({'videoId': videoId, 'startSeconds': startTime});
player.videoEnded = function () {
cb && cb();
};
player.waitForChanges();
}, 1000);
}
}
If I create variable startTime and hardcode some value in my js the player works. However I can seem to figure out what is wrong with line:
var startTime = videoId.getAttribute('data-start-time');
All I need to do is get the value assigned in html inside data-start-time="..." for each "li" using the ids that vary according to the specific "li"
videoIdargument? If it's a string containing the id of the element thenvideoId.getAttribute()is an error. Try$("#"+videoId).attr('data-start-time').