6

I'm using the following code trying to append a new row to jquery but it's not working.

$('#search-results > tbody').append('<tr><td data-th="Name">Test</td><td data-th="Email">test@test.com</td><td data-th="Phone Number">07777777777</td><td data-th="Car Reg.">ocf83or</td><td data-th="Time">1pm</td></tr>');

My table is setup like so:

<table class="view-bookings-table mobile-optimised hidden" id="search-results">
    <thead>
        <tr>
            <th scope="col">Name</th>
            <th scope="col">Email</th>
            <th scope="col">Phone Number</th>
            <th scope="col">Car Reg.</th>
            <th scope="col">Time</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

EDIT

My full code is actually:

$('#search').submit(function(event) {
    event.preventDefault();
    $('#search-results > tbody').append('<tr><td data-th="Name">Test</td><td data-th="Email">test@test.com</td><td data-th="Phone Number">07777777777</td><td data-th="Car Reg.">ocf83or</td><td data-th="Time">1pm</td></tr>');
});
V4n1ll4
  • 5,973
  • 14
  • 53
  • 92
  • 4
    [Your code works fine](http://jsfiddle.net/eestho47/). Did you include jQuery? And where/when is this script being called? – Ted Jun 10 '15 at 14:47
  • I have just added my full code as it's wrapped within a submit which maybe has something to do with it? – V4n1ll4 Jun 10 '15 at 14:55
  • Your code i already working if you use submit it should be place inside a form with an id search. Or try make it onclick first via button just to test your code. – Romeo Jun 10 '15 at 15:29
  • Seems to work fine? http://jsfiddle.net/n2L9t6qf/ – kspearrin Jun 10 '15 at 15:32

1 Answers1

4

Your code is fine and works well with every possible version of jQuery.

demo

You may have a jQuery error somewhere else on your page or you are not loading it. Also what is

class='hidden' 

doing? Maybe it's just a css issue?

boszlo
  • 1,144
  • 10
  • 14