1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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,500
    Likes Received:
    4,460
    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,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #3
    qwikad.com, Dec 6, 2016 IP