Possible Duplicate:
jQuery ajax return value
I have this jQuery script:
$('#headerSubmit').click(function() {
var source = $('#header').attr('value');
});
that gets the value attribute of the element and stores it in the source variable.
How do I return the source variable to use in the rest of the script?
Thanks.
As you would be setting the
sourcevariable after a click, any code that uses that variable should be executed only after such event. Therefore, you should paste your code right after it:Otherwise, the variable wouldn’t be initialized before a click.
Edit: Note all other answers incite you to declare the variable on global scope. This is useless unless your code executes after a click since the variable would be null.