javascript - Do function before confirm jquery -


here jquery code

$('.input').keyup(function(event){     update_text(); // $('div').html('blahblah'); }) .blur(function(event){     $(this).keyup();     if(confirm('are sure?')){         // somthing...     } }); 

my problem when input blur, confirm box should show after doing update_text();

but update_text() seems run after confirm...

how make update_text() first, show confirm dialog?

actually method run before confirm(), issue here browser repaints dom asynchronously though method .html() in synchronous. while doesn't appear run first visually indeed is.

for example more simple version have same functionality, can vary browser:

$("div").html("foo");  confirm('are sure?');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div></div>

one way around force dom repaint rather letting browser it. example:

$("div").html("foo");  $("div").hide().show(function(){    confirm('are sure?');   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div></div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -