How to simulate [mouseup ()] element by element using get ()

1

I have a web application which has elements of type input .

<input class="switch-input" name="0" type="checkbox" />
<input class="switch-input" name="1" type="checkbox" />
<input class="switch-input" name="2" type="checkbox" />
<input class="switch-input" name="3" type="checkbox" />

And I have a JavaScript code which I need to set these inputs to FALSE and simulate a MOUSEUP so that my application performs an action based on it. Basically I used:

$("input[type=checkbox]").prop("checked", false);
$("input").mouseup();

What worked very well initially, but in this case runs everything together and now I need a little delay. I tried to do:

$("input[type=checkbox]").prop("checked", false);
for(i=0;i < $("input").length; i++)
{
    setTimeout($("input")[i].mouseup(), 100);
}

But this returns me this error in console :

  

off-proc-rec.js: 29 Uncaught TypeError: $ (...) [i] .mouseup is not a function

I've also tried using:

 setTimeout($("input").eq(i).mouseup(), 100);

And I got this error:

  

VM811: 1 Uncaught SyntaxError: Unexpected identifier

Does anyone have any ideas on how to do this?

    
asked by anonymous 22.12.2016 / 17:52

1 answer

2

One option is to get the references of inputs by javascript, and within the loop, call a function to deselect by increasing the time between runs. Something like:

function go() {
  var inputs = document.querySelectorAll("input[type=checkbox]");
  var tempo = 100;
  for (var i = 0; i < inputs.length; i++) {
    var name = inputs[i].name;
    tempo = tempo + 500;
    desmarcar(name, tempo);
  }
}

function desmarcar(name, tempo){
    setTimeout(function() {
      $("input[name='"+name+"']").prop("checked", false);
      $("input[name='"+name+"']").mouseup();
    }, tempo);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputclass="switch-input" name="0" type="checkbox" />
<input class="switch-input" name="1" type="checkbox" />
<input class="switch-input" name="2" type="checkbox" />
<input class="switch-input" name="3" type="checkbox" />

<button onclick="go()">Testar</button>
    
22.12.2016 / 18:24