Learning jquery, in chrome console created form:
var $form1 = $("<form/>", { id: 'form1' });
$div1.append($form1);
Then tried to access the fields during form submission: This works:
$('#form1').submit(function(e) {
e.preventDefault();
$('#form1 input, #form1 select').each(function(index){
var input = $(this);
console.log('Type: ' + input.attr('type') + 'Name: ' + input.attr('name') + 'Value: ' + input.val());
});
});
But this does not:
$($form1).submit(function(e) {
e.preventDefault();
$($form1).each(function(index){
var input = $(this);
console.log('Type: ' + input.attr('type') + 'Name: ' + input.attr('name') + 'Value: ' + input.val());
});
});
How do I access the form fields using the variable $form1 instead of the actual element #form1?
Thanks for answer.