jquery - Returning variables outside a function -


i have been having problems returning variable through jquery function.

$(document).ready(function () {     var selected = "";      $('.whitetheme').on('click', function () {         $(this).effect("highlight", {}, 2000);         selected = "whitetheme";         return selected;          $('.blacktheme').fadeout(1500);         $('.redtheme').fadeout(1500);      })      console.log(selected); }); 

i trying have value of selected changed "whitetheme" once clicked.

right now, log function returns empty string.

you're binding event handler (and if invoked) change variable value. however, event cannot occur before console.log executed, don't see updated value.

also, blacktheme , redtheme classes not faded out, since code part unreachable.

what trying achieve?


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -