0

How can I execute two event at same time ? I do as following way. But it doesn't work properly. If I execute single at once, both work fine.

$(document).on('click', '#menu', function(){
    if($(this).is(':checked'))
          $(this).parent().find('ul').slideDown('slow');
    else
    // these two events
        $(this).parent().find('input[type="checkbox"]').prop('checked', false);
        $(this).parent().find('ul').hide('slow');
});
u_mulder
  • 54,101
  • 5
  • 48
  • 64
Dipak
  • 931
  • 14
  • 33
  • 3
    Those aren't event. Those are function calls. And you didn't surround them with `{}` if you want those last two statements to only happen for the else. Without `{}` after an if/else, only the next immediate statement will execute. – Taplar May 30 '18 at 17:08
  • 1
    You're missing brackets surrounding your two "events" that are not events :) – Bertrand May 30 '18 at 17:08
  • 1
    But still last line of code will be executed always. – u_mulder May 30 '18 at 17:10
  • @Taplar @Bertrand, I am still learning `jquery`, so new in term, got that difference between function and event. Now it works after adding `{}` . But It was still working though `{}` is missed for single line. – Dipak May 30 '18 at 17:15
  • 1
    This isn't a jQuery issue. This is a javascript syntax issue. When you write an if/else, it will only execute the next immediate statement after it. `if(conditional) else `. A statement is one single chain of commands. If you want to execute multiple statements as part of a conditional, you have to put them in `{}`. This makes them a statement block and is treated by the conditional as a single statement. – Taplar May 30 '18 at 17:19

0 Answers0