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 decode HTML character code in c#?
- How to save the xml file to a particular location?
- How to use if else statement in c++?
- How to use godaddy domain name with another godaddy hosting account?
- Restore of database 'DATABASE' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)
- How to programmatically modifying the AppSetting value in web.config using c#?
- TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
- How to calculate the age from jQuery ui datepicker using c#?
Related Article