I have this code
function getSelectData(id) {
jQuery(id).change(function () {
var value='';
jQuery(id+" option:selected").each(function () {
value =jQuery(this).val() ;
});
console.log(value);
});
return value;
}
var d = getSelectData("#sort_post_date");
console.log(d);
How i can access variable “value” , i tried different methods , but nothing , where is console.log(value); , value exit , but outside nothing , Thank You for Helping !
You need ot move value outside of the function so it is bound to the closure. Like this:
Here is the fiddle to show it works : http://jsfiddle.net/ZvuMh/