Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  196] [ 2]  / answers: 1 / hits: 55215  / 13 Years ago, mon, may 30, 2011, 12:00:00

Is there anyway that I can save or access a local variable outside of it's function? Consider the code below:



$( #droppable2 ).droppable({
activeClass: ui-state-hover,
hoverClass: ui-state-active,
accept: #draggable3,
drop: function( event, ui ) {

jdc = $(this).attr(id); //I need to use this value later
$( this )
.addClass( ui-state-highlight );
var x = ui.helper.clone();
x.appendTo('body');

var jdi = $(img).attr(id);// I need to use this value later

$(this).droppable( 'disable' );
}
});


Is there anyway to get the values of the two variables (jdc and jdi above) for later use outside of the function?



The ultimate goal is to get id of droppable container and content of dropped element.


More From » jquery

 Answers
35

try this:



jQuery(element).data(key,value);
// Store arbitrary data associated with the matched elements.


or declare your variable outside the function.



var example;

function abc(){
example = 12345;
}

abc();

console.log(example);

[#91968] Sunday, May 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
giovanny

Total Points: 314
Total Questions: 101
Total Answers: 90

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;