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):

    SEMrush
     
    Last edited by a moderator: Dec 4, 2016
    DeezyTech, Dec 4, 2016 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    25,166
    Likes Received:
    3,427
    Best Answers:
    100
    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:
    5,851
    Likes Received:
    1,084
    Best Answers:
    22
    Trophy Points:
    400
    #3
    qwikad.com, Dec 6, 2016 IP