Search code examples
javascriptjqueryformshidden-field

jQuery - Create hidden form element on the fly


What is the simplest way to dynamically create a hidden input form field using jQuery?


Solution

  • $('<input>').attr('type','hidden').appendTo('form');
    

    To answer your second question:

    $('<input>').attr({
        type: 'hidden',
        id: 'foo',
        name: 'bar'
    }).appendTo('form');