Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery create a form and add elements to it programmatically

Tags:

jquery

Hi I need to create a form and add elements to it programatically.

$form = $("<form></form>"); $form.append("<input type=button value=button"); 

this doesn't seem to work right.

like image 779
EBAG Avatar asked Dec 21 '10 07:12

EBAG


People also ask

How do you add an element to a form?

Create new elements by means of document. createElement() , and use appendChild() to append each of them to the container.

How can make HTML control dynamically using jQuery?

Create Dynamic Controlsappend() event with the control in which you want to add some dynamic controls and in that append event you need to write the HTML code similar to what you might have written in the body section and this will work for you, for example: <script> $(document). ready(function () {


1 Answers

You need to append form itself to body too:

$form = $("<form></form>"); $form.append('<input type="button" value="button">'); $('body').append($form); 
like image 57
Sarfraz Avatar answered Sep 29 '22 18:09

Sarfraz