JavaScript only working on first element

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
sds
Propeller Head
Posts: 48
Joined: Tue Jun 26, 2018 11:29 am
Location: Tucson

JavaScript only working on first element

Post by sds »

I am totally new at using JavaScript in MadCap Flare so bear with me.

I have a topic that will be dedicated to indexing videos. I added the videos as .webm (due to the secure browser we're using, and the sensitive information, we can't post our videos on YouTube). Adding the videos was easy enough but we wanted the "thumbnail" (really just the paused image of the video) to sit at 3 seconds in rather than at 0:00. I did some research and found JavaScript might be useful here.

On the topic that these videos will be indexed, I added the script:

Code: Select all

<script type="text/javascript">/*<![CDATA[*/$(document).ready(function() {
			v = document.querySelector('video');
			v.currentTime += 3;
		        });/*]]>*/</script>

It works great, but I just discovered that it only applies to the first <video> in the output. As soon as it gets to the second or third or fourth video, it's not applying. I tried creating a dedicated Master Page and applying the script there, but that didn't do the trick either.

Any ideas? Is there some other format I'm supposed to be using or another place I should put it?

EDIT: I believe I found my newb mistake. Need to use queryselectorall instead of queryselector. It's super late here so I'll be trying it out in the morning.

EDIT 2: After doing a bit more research on Java Script, I learned about some basic capital rules. My script that ended up performing the job (just in case anyone else who's new to JS has this problem):

Code: Select all

$(document).ready(function() {
   var videoArray = document.querySelectorAll('video');
   videoArray.forEach(function(videoElement) {
     videoElement.currentTime += 3
   });
});
Post Reply