var $div = $('<div class="error">').appendTo($('#header'));
When creating new elements and adding them to the DOM, do you need the ending tag? why or why not? Do I only need the ending tag if i'm placing content into the tag i'm creating? like so:
var $div = $('<div class="error"> Error-Homie! </div>').appendTo($('#header'));
or could I create an element with content in it, but leave out the ending tag? Good? Bad?
var $div = $('<div class="error">').appendTo($('#header'));
you can probably do it like this
You always need the ending tag to have proper html.
But it is a fact that the majority of browsers let such mistakes slip. It's no reason to be lazy, though, you should not rely on the browsers' tolerance for your code to work. This tolerance is there to be able to display sites with a few mistakes, not to caution deliberately incorrect code.
Although it may work if you don't use a closing tag (or at least self close the tag), you should add a closing tag (self-close) (as mentioned, for cross-platform compatibility):
This is how jQuery creates the elements:
Btw. you can also pass the data as second parameter:
you need the ending tag : http://api.jquery.com/appendTo/ for example
it should also be
and not