Add elements to DOM the right way

Add elements to DOM the right way

Hi all

So, I have a table with some rows and 3 columns in each row. I want to add a row with jQuery, what is the correct way?

I could do something like:
  1. $("table").append('<tr>
  2.         <td><h1>Example</h1><p>This is a sample</p></td>
  3.         <td><a href="#" class="link">A link</a></td>
  4.         <td class="nobg"><span class="test">This is a span</span></td>
  5. </tr>');

That just doesnt seem correct. I've seen people do stuff like
  1. jQuery('<div />').someStuffHere().appendTo('.someDiv');
 but I can't find any good documentation or examples.

Would somebody mind making an example of good practice with my first code example?

Thanks, Martin