Bootstrap class is not applied for dynamically added content

Viewed 720

I have a HTML & CSS combo like below

.panel-default.panel-custom {
    background: #05B9F0;
    color: white;
}
.headertext {
    text-align: center;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
      <script>
        $(document).ready(function(){
          $("#getdata").click(function(){
            var foobar  = $("#partnumbers").val();
            var urlToCall = "http://127.0.0.1:3000/foo?bar="+foobar
              $.getJSON(urlToCall, function(data, status){
                var markup = '';
                $.each(data, function(index) {
                  var key = index;
                  var value = data[index];
                  markup = markup + '<tr><td class="col-md-3">"'+key+'</td><td class="col-md-9">'+value+'</td></tr>'
                })
                markup = markup + "</table>";
                $("#data").append(markup);
                $("#data").addClass("table table-striped table-hover")
                $("#data").show()
              });
          });
      });
      </script> 
      <div class="panel panel-default panel-custom">
              <h2 class="headertext">
                  Foo Bar Status
              </h3> 
      </div>
        <div id=input-group class="input-group">
          <input type="text" id=partnumbers class="form-control" placeholder="Part Numbers">
            <span class="input-group-btn">
              <button class="btn btn-default" id="getdata" type="button" >View Data</button>
            </span>
        </div>
        <br>
        <br>
          <table id="data" style="display:none" >
            <thead>
              <tr>
                <th>Description</th>
                <th>Status</th>
              </tr>
            </thead>
          </table>
    </body>

As you can see, I am adding a style table table-striped table-hover to my table after appending the new markup I generated from data. I can see that the class is applied to the table when I inspect the element but in the browser, I am not able to see the effect of table table-striped table-hover. What am I missing here? I copied the entire content of <body> div from the developer tools window and placed it in a static HTML file. When I opened this static file in a browser, I was able to see the styling. But not when the page is served by the Node.js server. Any pointers here?

1 Answers
Related