PLEASE HELP! Toggle Play/Stop Button

Discussion in 'jQuery' started by DeezyTech, Dec 4, 2016.

  1. #1
    How do I make this into one button that toggles play/stop?


    $('.play').click(function() {
    $('#jquery-video').get(0).play();
    });
    $('.stop').click(function() {
    $('#jquery-video').get(0).pause();
    });
    
    $('.toggle').click(function() {
    if ($(this).hasClass('stopped')) {
    console.log("stopped");
    $(this).removeClass("stopped");
    $(this).addClass("playing");
    }
    else {
    console.log("playing");
    $(this).removeClass("playing");
    $(this).addClass("stopped");
    }
    });
    </script>
    Code (markup):
     
    Last edited by a moderator: Dec 4, 2016
    DeezyTech, Dec 4, 2016 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,851
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #2
    • Just have a variable that is equal to 1 or 0 that you check
    • Check to see what the class is, if it is "playing" change it to "stopped" else change to "playing"
     
    sarahk, Dec 4, 2016 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,330
    Likes Received:
    1,709
    Best Answers:
    31
    Trophy Points:
    475
    #3
    qwikad.com, Dec 6, 2016 IP