0

I want to make a button that if a guest button number 1, then button number 2 will be clicked and then pressed down for about 3 seconds, is it possible using jQuery?

I already tried using the mousedown() and click() but it doesnt press it down, only click. and already tried to googled it but doesnt found the solution

EDIT:

Here is the js file, it's a simple js that only need to be clicked and then pressed down for 3 seconds.

$(document).ready(function() {
  $('.turbo').on('click', function() {
    document.getElementById('status').innerHTML = 'Turbo clicked';

    $('.accelerate').click(function() {
        alert('accelerate clicked & pressed for 3 seconds');
    });
  });
});

1 Answers1

0

You can use this code below

var pressedDown = false,
clickedBtn = false;
$('button.btn1').click(function(){
    clickedBtn = true;
    $btn1 = $(this);
    $btn1.prop('disabled', true);
    setTimeout(function(){
        $btn1.prop('disabled', false);
    }, 10000);
})

$('button.btn2').on('mousedown', function(e){
    if(clickedBtn){
        pressedDown = true;
        setTimeout(function(){
            if(pressedDown){
                //run code here
            }
        }, 3000);
    }
}).on('mouseup', function(e){
    pressedDown = false;
})
KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31
  • the user didn't need to pressed down a button and hold it, it just need a single click and then hold the other button for 3 seconds – Khrisna Gunanasurya Jan 31 '19 at 08:39
  • okay... you want the user to click the first button once and then hold down the second button for 3 seconds? – KANAYO AUGUSTIN UG Jan 31 '19 at 08:45
  • yes, the second button will be hold down using jquery, so user only clicked the first button only. after he/she clicked the first button, first button will be disabled for 10 seconds, meanwhile the second button will hold down by jquery which is will give an extra boost for the speed, after 3 second, the user need to hold down the second button by himself but with a normal speed, (not the boosted speed) – Khrisna Gunanasurya Jan 31 '19 at 08:48
  • okay... i have editted my answer. and i believe thats your goal – KANAYO AUGUSTIN UG Jan 31 '19 at 08:57