Reputation: 32768
I have the following where $form is a jQuery object.
var $form = oSubmit.$form;
On this form I have input elements with a class of update-grid.
$('input.update-grid')
.each(function () {
var id = this.id.replace('modal', '');
$('#input' + id).val(this.value)
})
How can I tie these two together so that the function works on each input.update-grid on the $form object?
Upvotes: 0
Views: 75
Reputation: 1282
Try this:
$form.find('input.update-grid').each(function () {
var id = this.id.replace('modal', '');
$('#input' + id).val(this.value)
})
Upvotes: 0
Reputation: 339786
You can use
$('input.update-grid', $form).each(...)
which is actually just a wrapper for:
$form.find('input.update-grid').each(...)
Upvotes: 0
Reputation: 318182
Use the object in $form
as context :
$('input.update-grid', $form).each(function(index, elem) {
var id = elem.id.replace('modal', '');
$('#input' + id).val(elem.value)
});
Upvotes: 3