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 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
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article