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">[email protected]</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">[email protected]</td><td data-th="Phone Number">07777777777</td><td data-th="Car Reg.">ocf83or</td><td data-th="Time">1pm</td></tr>'); }); 
4
  • 4
    Your code works fine. Did you include jQuery? And where/when is this script being called? Commented Jun 10, 2015 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? Commented Jun 10, 2015 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. Commented Jun 10, 2015 at 15:29
  • Seems to work fine? jsfiddle.net/n2L9t6qf Commented Jun 10, 2015 at 15:32

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.