Search code examples
javascriptjqueryhtmlcssjquery-append

How to add div field dynamically in to a html page?


i tried to add a div field dynamically on clicking button but i am not getting response. here is my code.

<div id="#para">
  <tr class="divider"></tr>
  <tr>
    <td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>
    <td><input type="file" </td>
    <td><input type="time" placeholder="Enter Medicin Time"></td>
    <td><input type="date" placeholder="Enter Start Date"></td>
    <td><input type="date" placeholder="Enter End Date"></td>
  </tr>
  <tr class="divider"></tr>
</div>
<button type="submit" class="button" id="#btn1" value="Submit"><img src="images/plus.png"> Add More Notification</button>

Here Is My Js Code

$(document).ready(function(){
  $("#btn1").click(function(){
    $("#para").append('  <tr class="divider"></tr> <tr class="notification-row"><td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>  <td><input type="file" </td> <td><input type="time" placeholder="Enter Medicin Time"></td> <td><input type="date" placeholder="Enter Start Date"></td><td><input type="date" placeholder="Enter End Date"></td> </tr><tr class="divider"></tr>');
  });
});

Solution

  • Try this

    <div id="para">
      <tr class="divider"></tr>
      <tr>
        <td><input type="text" placeholder="Enter Medicin Name" style="width:80%;height:30px;"></td>
        <td><input type="file" </td>
        <td><input type="time" placeholder="Enter Medicin Time"></td>
        <td><input type="date" placeholder="Enter Start Date"></td>
        <td><input type="date" placeholder="Enter End Date"></td>
      </tr>
      <tr class="divider"></tr>
    </div>
    <button type="submit" class="button" id="btn1" value="Submit"><img src="images/plus.png"> Add More Notification</button>
    

    you should delete # on your HTML script

    in HTML (id) = jQuery (#) in HTML (class) = jQuery (.)

    you can source this on google