I have the ID of a selected textarea stored in a variable. Is it possible to use that variable to select the element by ID later on in the code? For example:
var currentTextarea = null;
function foo() {
currentTextarea = 'pageid'; // This will be set dynamically via an event. Example only.
}
function bar() {
$('#' + currentTextarea).val(); // Although this don't seem to work
}
yes, your code should work – be sure to call foo() before bar() otherwise it’be a null value…