How to Create a Text Box with jQuery?

Estimated read time 1 min read

To create a text box with jQuery, you can use the append() method to add an HTML element to the DOM. Here’s an example code snippet:


<div id="textbox-container"></div>


$(document).ready(function() {
  $('#textbox-container').append('<input type="text" id="textbox" placeholder="Enter text here"/>');


  1. The $(document).ready() function ensures that the jQuery code is executed only after the page has finished loading.
  2. The $('#textbox-container').append() function appends an input element with type="text" and id="textbox" to the div element with id="textbox-container".
  3. The placeholder attribute sets the initial text in the text box before the user enters any text.

When the page is loaded, the jQuery code will add an input element to the div container with id="textbox-container". The input element will be a text box with a placeholder text “Enter text here”. You can customize the input element by modifying the attributes and properties of the element.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply