locked
javascript RRS feed

All replies

  • User281315223 posted

    Are you using the same code as the example provides? It looks to be working as expected (e.g. clicking the button hides the paragraph and displays the dialog). If you wanted to show your dialog explicitly after the hidden, you can pass a completion function to the hide call as a callback:

    $('p').hide(0, function(){ alert('The element has been hidden!'); });

    You might consider posting your exact code if this still isn't working for you. 

    Wednesday, March 11, 2020 9:05 PM
  • User87195929 posted

    no sir,

    my question 

    why $("p").hide(1000) is not executed  at the beginning,

    why it wait  until alert method is finished

    Thursday, March 12, 2020 5:00 AM
  • User-1330468790 posted

    Hi, siddangoud,

    Actually, "$("p").hide(1000)" does not wait until the alert method is finished. It starts and then the function 'alert' takes place to popup.

    '1000' here means the hide animation will complete in 1 second. If you try to set the time from '1000' to '5000' and click the 'OK' button immediately. You will see the process of the hide animation.

    What @Rion Williams provide you is a solution how to make the alert waiting for the end of the hide animation. You can copy that and replace the code for $("p") and you will find the 'alert' function should only be able to work after the 'p' element hided.

    Hope this can help you.

    Best regards,

    Sean

     

    Thursday, March 12, 2020 6:37 AM
  • User87195929 posted

    <script>
    $(document).ready(function(){
    $("button").click(function(){

    alert("The paragraph is now hidden");
    });
    });
    </script>

    my question is simple

    why $("p").hide(); code execuated after alert("The paragraph is now hidden");

    Thursday, March 12, 2020 6:43 AM
  • User-1330468790 posted

    Hi, siddangouod,

     

    Don't be deceived by the visual effect. 

    $("p").hide(); code does execute before alert("The paragraph is now hidden");

     

    The reason why you can see alert popup before that transition is that Jquery's transition of the 'p' element from 'visible' to 'hidden' has a duration of 1000 ms (1 second), so as it proceeds, the javascript parser continues for the rest of the script. 

    Then the parser arrives at the postion of the alert function before the duration '1000 ms' exhausted so that you find the alert popup but the 'p' element has not become hidden.

     

    Best regards,

    Sean

    Thursday, March 12, 2020 7:22 AM