Reputation: 5591
So, I have a following js var:
var rhpp_id = jQuery(this).parents('.rhp').data("pi");
This is inside of function. However I am using the same line in multiple functions and I was wondering if there is a way of making this exact line as a global variable that I can use in other functions.
Thanks.
Upvotes: 0
Views: 40
Reputation: 5109
Define a var outside of your functions and set it's value inside the function where $(this) is valid:
var rhpp_id = "";
$('#divname').click(function () {
rhpp_id = jQuery(this).parents('.rhp').data("pi");
});
Then you can access it globally.
Upvotes: 1