On Thu, Sep 24, 2009 at 12:53 PM, Bertilo Wennergren <berti...@gmail.com>wrote:

>
> Richard D. Worth wrote:
>
>  Best practice, valid HTML, and compatible with XHTML would be
>> $('#whatever').html('<div></div>');
>> $('#whatever').html('<br />');
>> $('#whatever').html('<img alt="" src="..." />');
>>
>
> Well, not quite "valid" HTML...
>

quite valid. See in the below paragraph "That means that '<br />' is valid"


>
> If you use "<br />" in an HTML 4.01 page, the validator at
> "w3.org" gives a warning with the following explanation:
>
>  The sequence <FOO /> can be interpreted in at least two different
>  ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict,
>  the '/' terminates the tag <FOO (with an implied '>'). However, since
>  many browsers don't interpret it this way, even in the presence of an
>  HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure
>  HTML documents and reserve its use solely for those written in XHTML.
>
> That means that "<br />" is valid, but it does not mean what
> it was supposed to mean (in HTML 4.01). It means "<br>>"!
>

Having to ignore this warning is a pain, and that's remedied by HTML5. As I
posted previously, in HTML5 it is allowed (not recommended nor required)
because it's in such common use for compatibility with XHTML.


> Still, it's not likely that any browser will actually
> produce "<br>>" "from $('#whatever').html('<br />')".
> But we're talking "best practices" here.


One best practice I have is that any (X)HTML I write should require as
little modification as possible to be made one or the other. The HTML5 spec
and FAQ give me confidence that no useful browser or html parser will do
"the wrong thing" with <br /> parsed as text/html, so it's worth the
potential ease of migration to/from XHTML. If nothing else, it's a best
practice that allows one to read and write HTML and XHTML without having to
remember as much.

- Richard

Reply via email to