0

I have a page with a video in it (using video_tag); the video url is stored in an instance variable in my controller. I'm trying to use jQuery to write my own controls for the video, but I can't seem to make it work.

I am certain that the javascript is rendering properly, because I've replaced the video-related code in the click event with a simple function that changes the background color, and it worked

This makes me believe that I'm improperly targeting the video itself since I'm using video_tag and adding a class attribute instead of an html video tag.

Here is my html and my javascript, including the video_tag and the button:

<div id="video-container">
  <%= video_tag @video, class: "actual-video" %>
  <button class="playbutton">Play or Pause</div>
</div>

<script>
$(".playbutton").on("click", function() {
    if (".actual-video").paused {
        $( ".actual-video" ).play();
    } else {
        $(".actual-video").pause();
    }
});

I'm calling on the expertise of some Ruby on Rails peeps to tell me if there's something I need to know about properly targeting a video using video_tag and the class attribute. I believe that this is the problem, but if any of you spot anything fundamentally wrong with my code, please let me know! Thanks in advance!!!

Parker
  • 493
  • 1
  • 4
  • 14
  • 1
    See this: http://stackoverflow.com/questions/4646998/play-pause-html-5-video-using-jquery – J Plato May 04 '16 at 18:18
  • Oh my gosh thank you so much. I looked for a similar question and couldn't find one. Thank you very much J Plato. I hope the rest of your day goes well! – Parker May 04 '16 at 18:20
  • 1
    I went through the same thing a while ago. good luck! – J Plato May 04 '16 at 18:22
  • @JPlato Were you using ruby on rails when you had this issue? If so, is the class you used in the javascript the same class set the video_tag to be? – Parker May 04 '16 at 18:28
  • 1
    Yes, Rails app. I used the id, not the class, but it should work with a class selector as well. I did something along these lines: $("#my_video").trigger("play"); – J Plato May 04 '16 at 19:42
  • @JPlato Thanks a lot man. I've got it working now. Couldn't have done it without you, you've really helped me out a ton. Thanks and goodbye again :) – Parker May 04 '16 at 21:24

0 Answers0