Click here to Skip to main content
16,017,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to create new text box on click of a button with jQuery. I tried several codes from different websites. One of them is:

XML
var newDiv = $(document.createElement('div')).attr("id", 'my' + num + 'Div');
               newDiv.append().html('<input type="text"  name="TextBox' + num + '" value="TextBox' + num + '" >');
               newDiv.appendTo("#Div1");



Still when i click on button, nothing happens
What is wrong in my code?
Posted

1 solution

newDiv.appendTo("#Div1");

This is not using jquery to look up div1. you need $("#Div1") for that. I recommend looking up Div1 first, just to make your code more readable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900