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.
jQuery(element). data(key,value); // Store arbitrary data associated with the matched elements. or declare your variable outside the function.
In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery. A (selector) to "query (or find)" HTML elements.
You can read about Local Storage here. // save data value localStorage. setItem("name", "John"); // retrieve data value var name = localStorage. getItem("name");
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With