I added a class of "vid-active" to divs. Only one div can have it at a time. I now try to do this:
$('.kol-vid-select').click(function(){
var clicked = $(this);
$('.kol-vid-select').removeClass('vid-active');
clicked.addClass('vid-active');
if($('.vid-active').hasClass('overview')){
$('#myvid').attr('src', 'http://player.vimeo.com/video/108161058?api=1&player_id=player1');
counter=0;
//alert('overview');
}
if($('.vid-active').hasClass('analysis')){
$('#myvid').attr('src', 'https://player.vimeo.com/video/125471793?api=1&player_id=player1');
counter=0;
//alert('analysis');
}
if($('.vid-active').hasClass('compelling')){
$('#myvid').attr('src', 'https://player.vimeo.com/video/125478290?api=1&player_id=player1');
counter=0;
//alert('compelling');
}
if($('.vid-active').hasClass('practical')){
$('#myvid').attr('src', 'https://player.vimeo.com/video/125483119?api=1&player_id=player1');
counter=0;
//alert('practical');
}
if($('.vid-active').hasClass('proven')){
$('#myvid').attr('src', 'https://player.vimeo.com/video/125483160?api=1&player_id=player1');
counter=0;
//alert('proven');
}
});
//------------------------------------------------------
var counter = 0;
$(function() {
//alert('in here');
var player = $('iframe');
var playerOrigin = '*';
var status = $('.status');
// Listen for messages from the player
if (window.addEventListener) {
window.addEventListener('message', onMessageReceived, false);
}
else {
window.attachEvent('onmessage', onMessageReceived, false);
}
// Handle messages received from the player
function onMessageReceived(event) {
//alert('lept going');
// Handle messages from the vimeo player only
if (!(/^https?:\/\/player.vimeo.com/).test(event.origin)) {
return false;
}
if (playerOrigin === '*') {
playerOrigin = event.origin;
}
var data = JSON.parse(event.data);
switch (data.event) {
case 'ready':
onReady();
break;
case 'playProgress':
onPlayProgress(data.data);
break;
}
}
// Helper function for sending a message to the player
function post(action, value) {
var data = {
method: action
};
if (value) {
data.value = value;
}
var message = JSON.stringify(data);
player[0].contentWindow.postMessage(data, playerOrigin);
}
function onReady() {
post('addEventListener', 'playProgress');
}
function onPlayProgress(data) {
//alert('Hello!');
if (true) {};
if (true) {};
if (true) {};
if (true) {};
if (true) {};
alert(counter);
if ($(".vid-active").hasClass("overview")&&(counter==0)) {
alert("This");
counter = counter + 1;
ga('send','event', 'KOL Video', 'Start', 'Chapter 1 - Overview');
};
if ($(".vid-active").hasClass("analysis")) {
alert("is");
counter = counter + 1;
ga('send','event', 'KOL Video', 'Start', 'Chapter 2 - Compounding');
};
if ($(".vid-active").hasClass("compelling")) {
alert("SPARTA");
counter = counter + 1;
ga('send','event', 'KOL Video', 'Start', 'Chapter 3 - FDA-Approved');
};
if ($(".vid-active").hasClass("practical")) {
alert("AAAAA!");
counter = counter + 1;
ga('send','event', 'KOL Video', 'Start', 'Chapter 4 - Co-pay');
};
if ($(".vid-active").hasClass("proven")) {
alert("!!!!!!!");
counter = counter + 1;
ga('send','event', 'KOL Video', 'Start', 'Chapter 5 - Epaned');
};
}
});
But when I click on any div other than the first div, (thus activating it). the new div gets the styles from "vid-active" applied but JQuery does not fire the appropriate alert.
Why is this and how do I fix it?