I am failing to target an div when this div has a certain id if the current page had
<div id="global">
<div id="videosContainer" data-has-video="1" data-video= "youtube">
<iframes here> and some content
</div>
<div id="content"> </div>
</div>
I need to listen to clicks on the #content area on pages where the current state/DOM of the page has inside the div with id #videosContainer a data-video= "youtube".
The difficulty is to target an area based on if another div (same level in the DOm= descendant of #global) has a certain data attribute.
var $clickableAreaForStateWithYoutube = $('#content #videosContainer[data-video] = "youtube"');
$clickableAreaForStateWithYoutube.on('click', function(e) {
alert("a click was performed while a youtube video was playing")
resetTimer("timer");
//do stuff
});
If the value is not "youtube", i don't want the event that I define on my listener below to kick in. that's why I need to target only pages whose current state have data-attribute="youtube"
Values of the data attribite "data-video' can be:
"youtube"
"vimeo"
does not exist: in which case it's NOT that there is data-video="" but there is just no data-video inside the div (if needed I could change this behavior to have data-video="")
If possible, I'd rather find an actual way to target the element with jquery, that is to say find a way to define the area, and not to just add everytime (a lof of times in my codebase) do some condition (something along the line of adding inside the $clickableAreaForStateWithYoutube.on click listener a if #videosContainer has data-video equal to "youtube")