Ok, what I am after is quite simple. I have click handler for multiple radio group sets. Inside the handler I am passing some parameters to a functions parameters references are relative to the group set but their path are the same. So I basically have:
$(document).ready(function(){
$("input[name='radioGroup1']").click(function(){
updateWalletInfo(
$(this).val(),
$(this).parent().parent().find(".cSec .f_class a").text(),
$(this).parent().parent().parent().find(".cSec .flight-time").text(),
$(this).parent().parent().parent().find(".cSec .city").text(),
);
});
$("input[name='radioGroup2']").click(function(){
updateWalletInfo(
$(this).val(),
$(this).parent().parent().find(".cSec .f_class a").text(),
$(this).parent().parent().parent().find(".cSec .flight-time").text(),
$(this).parent().parent().parent().find(".cSec .city").text(),
);
});
});
What I want to do is to save reference to particular item under $(document).ready()
so if I change the path I wouldn't have to change it in each handler. Like what I am after is like:
$(document).ready(function(){
var value = $(this).val();
var f_class = $(this).parent().parent().find(".cSec .f_class a").text();
var f_time =$(this).parent().parent().parent().find(".cSec .flight-time").text();
var f_city = $(this).parent().parent().parent().find(".cSec .city").text();
$("input[name='radioGroup1']").click(function(){
updateWalletInfo(value,f_class,f_time,f_city);
});
$("input[name='radioGroup2']").click(function(){
updateWalletInfo(value,f_class,f_time,f_city);
});
});
I know the this operator will not work there, but I thought that makes my point more clear. I am even happy if I could only remove the redundancy for .parent().parent().find(".cSec .????").text()
bit.