In this article, I will show you how to create a textbox control dynamically in JQuery. You can add textbox using keyword attr and pass a parameter of textbox attribute fields such as text, name, id etc. and append to the div element.
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
<script type="text/javascript">
$(document).ready(function () {
var $ctrl = $('<input/>').attr({ type: 'text', name: 'text', placeholder: 'text' }).addClass("text");
$("#divcontent").append($ctrl);
});
</script>
<body style="border:1px solid #0094ff;padding:5px 10px 5px 10px;width:500px;height:350px">
<div class="container">
<div class="row">
<h2> how to add text box dynamically using JQuery</h2>
<button id="btnGenerate" >Generate Text Control</button>
<br />
<i>click above button</i>
<div id="divcontent"></div>
</div>
</div>
</body>
Output:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article