I am a newbie to the jquery. I am trying to access a variable defined inside jquery block outside the jquery (from regular function) like this, but I can't access it. Could somebody tell me how?
<script language="javascript">
$(function()
{
.......
.......
.......
var api = pane.data('jsp');
var current_location = api.getContentPositionX();
}
function change_title(t_index) {
alert("print="+$.current_location);
window.location.href="page.php?p="+$.current_location);
}
I want to get a value for $.current_location.
Thanks.
There is no such thing as a "jQuery variable", they are all regular Javascript varaibles.
The reason that you can't access the current_location
variable from your function is that the variable is declared locally inside another function.
Just declare the variable outside the functions so that it's global, and you can access it from both functions:
var current_location;
$(function() {
.......
.......
.......
var api = pane.data('jsp');
current_location = api.getContentPositionX();
}
function change_title(t_index) {
alert("print=" + current_location);
window.location.href = "page.php?p=" + current_location;
}
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