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:
- $("table").append('<tr>
- <td><h1>Example</h1><p>This is a sample</p></td>
- <td><a href="#" class="link">A link</a></td>
- <td class="nobg"><span class="test">This is a span</span></td>
- </tr>');
That just doesnt seem correct. I've seen people do stuff like
- 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