Setting the value for all input fields of a class foo
is easy:
$('#long .path .to .foo').val('...');
But now I need to manipulate the foo
fields at multiple places, so I saved it as object as want to use it like this:
foo = $('#long .path .to .foo');
foo.val('...');
When I assign the value within the function, where I use it, it works. But when this doesn't work:
$(document).ready(function() {
foo = $('#long .path .to .foo');
bar();
}
function bar() {
foo.val('...');
}
And it's not about the scope, since this works:
function bar() {
foo.first().val('...'); // or last()
}
How to set the value
of all elements of a class
using a jQuery object saved to a variable (outside the current scope)?