I am trying to convert a jquery
function to vanila js
.I don't know the implementation of that function I just want to convert jquery
function to javascript . here is my jquery function.
jQuery('button.vjs-share-control').on('touchstart click', function(e) {
e.preventDefault();
if(e.type == "touchstart") {
var embedDiv = jQuery(this).closest('div.bcvideo');
var vid = videojs(embedDiv.data('bcobjid'));
var shareopts = {
"services": setSocialLinks.call(embedDiv)
};
// set share links
vid.social(shareopts);
jQuery('#w10close').removeClass('hidden');
} else if(e.type == "click") {
var embedDiv = jQuery(this).closest('div.bcvideo');
var vid = videojs(embedDiv.data('bcobjid'));
var shareopts = {
"services": setSocialLinks.call(embedDiv)
};
// set share links
vid.social(shareopts);
jQuery('#w10close').removeClass('hidden');
}
});
I covert this function to javascript but I am confused by closest
and call
function how to convert these jquery
function to javascript.
Here is my javascript function (converted jquery function to javascript)
document.querySelector('button.vjs-share-control').addEventListener('touchstart click', function(e) {
e.preventDefault();
if(e.type == "touchstart") {
var embedDiv = document.querySelector(this).closest('div.bcvideo');
var vid = videojs(embedDiv.data('bcobjid'));
var shareopts = {
"services": setSocialLinks.call(embedDiv)
};
// set share links
vid.social(shareopts);
document.querySelector('#w10close').classList.remove('hidden');
} else if(e.type == "click") {
var embedDiv = document.querySelector(this).closest('div.bcvideo');
var vid = videojs(embedDiv.data('bcobjid'));
var shareopts = {
"services": setSocialLinks.call(embedDiv)
};
// set share links
vid.social(shareopts);
document.querySelector('#w10close').classList.remove('hidden');
}
});
is it a right converted function ?