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
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
Related Article