title: How can I dynamically add bootstrap alerts to a page using javascript?
body: <p>I'm working on creating a todo list using Bootstrap. <a href="https://i.stack.imgur.com/JoDo4.png" rel="nofollow noreferrer">Here's how I'd like it to look</a>. I've created the form and know how to access the data in the form.</p>
  
  <p>What I don't know how to do is dynamically add the alerts to the page using JavaScript upon clicking the submit button. I'd like the alerts to be a part of the bootstrap grid and scale accordingly with resizing the window. </p>
  
  <p>HTML I'm using below with a variation of Sheikh's answer for the JS. I think I should be able to figure out the rest from here. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myAlert(task, days) {
    const wrapper = document.createElement('div');
    wrapper.innerHTML = 
    `&lt;div class="alert alert-warning alert-dismissible fade show" role="alert"&gt;
      ${task}&lt;/br&gt;${days}
      &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
      &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
    &lt;/button&gt;
      &lt;/div&gt;`;
    document.body.appendChild(wrapper);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;!-- Required meta tags --&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"&gt;
  
      &lt;!-- Bootstrap CSS --&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"&gt;
      
      &lt;!-- Script to add tasks--&gt;
      &lt;script src=scripts.js&gt;&lt;/script&gt;
  
      &lt;title&gt;To-do list&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div class="container"&gt;
  
            &lt;h1 style="text-align: center"&gt;Todo List&lt;/h1&gt;
  
            &lt;form name="form1" action="" onsubmit="event.preventDefault(); myAlert(document.getElementById('task').value, document.getElementById('days').value)"&gt;
                &lt;div class="form-group"&gt;
                    &lt;label for="task"&gt;Task&lt;/label&gt;
                    &lt;input id="task" class="form-control" type="text" name="task" required&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                    &lt;label for="days"&gt;Days To Complete&lt;/label&gt;
                    &lt;input id="days" class="form-control" type="text" name="task"  required&gt;
                &lt;/div&gt;
                &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
            &lt;/form&gt;
            &lt;hr/&gt;
      &lt;/div&gt;
  
      &lt;!-- Optional JavaScript --&gt;
      &lt;!-- jQuery first, then Popper.js, then Bootstrap JS --&gt;
      &lt;script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>