do something before confirm dialog pops up





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0


















$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>





So I firstly want to hide the div and then pop up the confirm dialog. Is it possible?










share|improve this question


















  • 1





    Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

    – Jay Harris
    Nov 24 '18 at 20:50













  • You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

    – Jay Harris
    Nov 24 '18 at 20:52











  • window.requestAnimationFrame()

    – Jay Harris
    Nov 24 '18 at 20:54











  • @JayHarris, don't tell me pls that I need to use entire API to hide a div?

    – user7461846
    Nov 24 '18 at 20:57






  • 2





    hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

    – Tieson T.
    Nov 24 '18 at 21:18


















0


















$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>





So I firstly want to hide the div and then pop up the confirm dialog. Is it possible?










share|improve this question


















  • 1





    Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

    – Jay Harris
    Nov 24 '18 at 20:50













  • You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

    – Jay Harris
    Nov 24 '18 at 20:52











  • window.requestAnimationFrame()

    – Jay Harris
    Nov 24 '18 at 20:54











  • @JayHarris, don't tell me pls that I need to use entire API to hide a div?

    – user7461846
    Nov 24 '18 at 20:57






  • 2





    hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

    – Tieson T.
    Nov 24 '18 at 21:18














0












0








0











$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>





So I firstly want to hide the div and then pop up the confirm dialog. Is it possible?










share|improve this question

















$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>





So I firstly want to hide the div and then pop up the confirm dialog. Is it possible?






$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>





$('.lorem').on('click', function(){
$(this).hide();
if(prompt('DO SOMETHING') != null) {console.log('something');}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='lorem'>lorem</div>






javascript jquery confirm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 20:48







user7461846















  • 1





    Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

    – Jay Harris
    Nov 24 '18 at 20:50













  • You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

    – Jay Harris
    Nov 24 '18 at 20:52











  • window.requestAnimationFrame()

    – Jay Harris
    Nov 24 '18 at 20:54











  • @JayHarris, don't tell me pls that I need to use entire API to hide a div?

    – user7461846
    Nov 24 '18 at 20:57






  • 2





    hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

    – Tieson T.
    Nov 24 '18 at 21:18














  • 1





    Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

    – Jay Harris
    Nov 24 '18 at 20:50













  • You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

    – Jay Harris
    Nov 24 '18 at 20:52











  • window.requestAnimationFrame()

    – Jay Harris
    Nov 24 '18 at 20:54











  • @JayHarris, don't tell me pls that I need to use entire API to hide a div?

    – user7461846
    Nov 24 '18 at 20:57






  • 2





    hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

    – Tieson T.
    Nov 24 '18 at 21:18








1




1





Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

– Jay Harris
Nov 24 '18 at 20:50







Yes throw the prompt in an animation frame window.requestAnimationFrame(() => {if(prompt('DO SOMETHING') != null) {console.log('something');} }

– Jay Harris
Nov 24 '18 at 20:50















You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

– Jay Harris
Nov 24 '18 at 20:52





You may have to do a nested animation frame callback as one will run before the next repaint eg: requestAnimationFrame(() => { /* div is about to be hidden on next paint*/ requestAniamtionFrame(() => { /* div was hidden on last paint */} })

– Jay Harris
Nov 24 '18 at 20:52













window.requestAnimationFrame()

– Jay Harris
Nov 24 '18 at 20:54





window.requestAnimationFrame()

– Jay Harris
Nov 24 '18 at 20:54













@JayHarris, don't tell me pls that I need to use entire API to hide a div?

– user7461846
Nov 24 '18 at 20:57





@JayHarris, don't tell me pls that I need to use entire API to hide a div?

– user7461846
Nov 24 '18 at 20:57




2




2





hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

– Tieson T.
Nov 24 '18 at 21:18





hide accepts a callback function, for when the animation is complete: api.jquery.com/hide/#hide-duration-complete -move your prompt there

– Tieson T.
Nov 24 '18 at 21:18












2 Answers
2






active

oldest

votes


















1














Use animation frames to run code before the next paint.



window.requestAnimationFrame()



$('.lorem').on('click', function(){
// The browser will paint async not sync, so the div may still be visible
// even after this line
$(this).hide();
// when the browser is ready to paint the div off screen the callback will fire
window.requestAnimationFrame(() => {
if (prompt('DO SOMETHING') != null) {
console.log('something');
}
});
});


note: You may have to do nested animation frames as browsers tend to implement request animation frame differently.



requestAnimationFrame(() => requestAnimationFrame(() => {
...
}));





share|improve this answer































    0














    You can use a setTimeout:



     document.querySelector('.lorem').addEventListener('click',  () => {
    document.querySelector('.lorem').style.display = "none";
    setTimeout(() => {
    if(prompt("do something") !== null) {
    console.log('do something')
    }
    }, 100)
    })





    share|improve this answer



















    • 2





      note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

      – Jay Harris
      Nov 24 '18 at 21:15











    • Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

      – Dmitriy
      Nov 24 '18 at 21:19












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462240%2fdo-something-before-confirm-dialog-pops-up%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Use animation frames to run code before the next paint.



    window.requestAnimationFrame()



    $('.lorem').on('click', function(){
    // The browser will paint async not sync, so the div may still be visible
    // even after this line
    $(this).hide();
    // when the browser is ready to paint the div off screen the callback will fire
    window.requestAnimationFrame(() => {
    if (prompt('DO SOMETHING') != null) {
    console.log('something');
    }
    });
    });


    note: You may have to do nested animation frames as browsers tend to implement request animation frame differently.



    requestAnimationFrame(() => requestAnimationFrame(() => {
    ...
    }));





    share|improve this answer




























      1














      Use animation frames to run code before the next paint.



      window.requestAnimationFrame()



      $('.lorem').on('click', function(){
      // The browser will paint async not sync, so the div may still be visible
      // even after this line
      $(this).hide();
      // when the browser is ready to paint the div off screen the callback will fire
      window.requestAnimationFrame(() => {
      if (prompt('DO SOMETHING') != null) {
      console.log('something');
      }
      });
      });


      note: You may have to do nested animation frames as browsers tend to implement request animation frame differently.



      requestAnimationFrame(() => requestAnimationFrame(() => {
      ...
      }));





      share|improve this answer


























        1












        1








        1







        Use animation frames to run code before the next paint.



        window.requestAnimationFrame()



        $('.lorem').on('click', function(){
        // The browser will paint async not sync, so the div may still be visible
        // even after this line
        $(this).hide();
        // when the browser is ready to paint the div off screen the callback will fire
        window.requestAnimationFrame(() => {
        if (prompt('DO SOMETHING') != null) {
        console.log('something');
        }
        });
        });


        note: You may have to do nested animation frames as browsers tend to implement request animation frame differently.



        requestAnimationFrame(() => requestAnimationFrame(() => {
        ...
        }));





        share|improve this answer













        Use animation frames to run code before the next paint.



        window.requestAnimationFrame()



        $('.lorem').on('click', function(){
        // The browser will paint async not sync, so the div may still be visible
        // even after this line
        $(this).hide();
        // when the browser is ready to paint the div off screen the callback will fire
        window.requestAnimationFrame(() => {
        if (prompt('DO SOMETHING') != null) {
        console.log('something');
        }
        });
        });


        note: You may have to do nested animation frames as browsers tend to implement request animation frame differently.



        requestAnimationFrame(() => requestAnimationFrame(() => {
        ...
        }));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 22:05









        Jay HarrisJay Harris

        3,7201320




        3,7201320

























            0














            You can use a setTimeout:



             document.querySelector('.lorem').addEventListener('click',  () => {
            document.querySelector('.lorem').style.display = "none";
            setTimeout(() => {
            if(prompt("do something") !== null) {
            console.log('do something')
            }
            }, 100)
            })





            share|improve this answer



















            • 2





              note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

              – Jay Harris
              Nov 24 '18 at 21:15











            • Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

              – Dmitriy
              Nov 24 '18 at 21:19
















            0














            You can use a setTimeout:



             document.querySelector('.lorem').addEventListener('click',  () => {
            document.querySelector('.lorem').style.display = "none";
            setTimeout(() => {
            if(prompt("do something") !== null) {
            console.log('do something')
            }
            }, 100)
            })





            share|improve this answer



















            • 2





              note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

              – Jay Harris
              Nov 24 '18 at 21:15











            • Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

              – Dmitriy
              Nov 24 '18 at 21:19














            0












            0








            0







            You can use a setTimeout:



             document.querySelector('.lorem').addEventListener('click',  () => {
            document.querySelector('.lorem').style.display = "none";
            setTimeout(() => {
            if(prompt("do something") !== null) {
            console.log('do something')
            }
            }, 100)
            })





            share|improve this answer













            You can use a setTimeout:



             document.querySelector('.lorem').addEventListener('click',  () => {
            document.querySelector('.lorem').style.display = "none";
            setTimeout(() => {
            if(prompt("do something") !== null) {
            console.log('do something')
            }
            }, 100)
            })






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 24 '18 at 21:13









            DmitriyDmitriy

            633316




            633316








            • 2





              note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

              – Jay Harris
              Nov 24 '18 at 21:15











            • Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

              – Dmitriy
              Nov 24 '18 at 21:19














            • 2





              note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

              – Jay Harris
              Nov 24 '18 at 21:15











            • Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

              – Dmitriy
              Nov 24 '18 at 21:19








            2




            2





            note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

            – Jay Harris
            Nov 24 '18 at 21:15





            note that settimeout doesn't guarantee to run before the next repaint. In theory JavaScript can run multiple task before deciding to repaint.

            – Jay Harris
            Nov 24 '18 at 21:15













            Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

            – Dmitriy
            Nov 24 '18 at 21:19





            Seems like OP was looking for a simple solution based on the way he reacted to your answer, so I gave him one

            – Dmitriy
            Nov 24 '18 at 21:19


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462240%2fdo-something-before-confirm-dialog-pops-up%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Xamarin.form Move up view when keyboard appear

            JBPM : POST request for execute process go wrong