I just need the logic and understanding on how I can do this.
The problem:
I have several functions that are very similar but I want to create/call the dynamically
Example:
$(document).ready(function() {
function foo() {
$("#foo_elem").toggle(true).attr('required', true);
alert('This is foo');
}
function bar() {
$("#bar_elem").toggle(true).attr('required', true);
alert('This is bar');
}
});
How can I pass in foo/bar to create the function? Pseudo code
$(document).ready(function() {
// would pass foo/bar to this?
$($x)(function() {
$("#"+$(this)+"_elem").toggle(true).attr('required', true);
alert('This is '+$(this));
});
});