Have next script:
function clicker(){
var linkId = "[id*=" + "link]";
var butnId='initial';
$j(linkId).click(function(){
var postfix = $j(this).attr('id').substr(4);
butnId = '#' + 'butn' + postfix;
});
return butnId;
}
Function output is ‘initial’ value.
How to return actual value of variable butnId,after it had been transformed within click function?
The code inside the function passed to
clickdoesn’t get executed until the element is clicked.You probably need the caller of
clickerto pass in a callback function that can then be called by the click function (assuming you don’t want to hardcode the required action into the click function itself):-Which likely can be refactored to:-