Eric Teixeira
Eric Teixeira

Reputation: 353

How can I execute two actions at the same time?

I'm using this script to execute two actions.

It's a toggle for #mobileJ and #botaojs but they aren't executing at the same time; I would like to make both actions happen together.

$(document).ready(function(){
  $("#namala").click(function(){
    $("#mobileJ").toggle(function () {
      $("#botaojs").toggleClass("toggleclass");
    });            
  });
});

Upvotes: 1

Views: 1215

Answers (2)

Eloims
Eloims

Reputation: 5224

Don't put the second action in a callback

<!-- Script Jquery -->
<script>
    $(document).ready(function(){
      $("#namala").click(function(){
        $("#botaojs").toggleClass("toggleclass");
        $("#mobileJ").toggle();
      });
    });
</script>

Upvotes: 0

David
David

Reputation: 218808

The callback function for .toggle() happens after it's complete, not at the same time. In order for both to happen simultaneously (at least observed simultaneously, though there's likely some millisecond-delay), don't use the callback. Just execute them both:

$("#mobileJ").toggle();
$("#botaojs").toggleClass("toggleclass");

Upvotes: 3

Related Questions