I’m looking for a list of HTML elements who should have parent elements (other than <body>) for them to make the most sense.
For example, a <tr> element would be one such element because it should be inside of a <tbody> or <table> element. A <div> element would not be such an element because it is perfectly fine being inside of a <body> element directly.
Does anyone know of the best way to get such a list? I found this list as a starting point, but it would save me some time if there was a better way than me checking each one individually.
For versions of HTML prior from HTML 2.0 to HTML 4.01 and XHTML 1.x, see their DTD(s) (which are linked from the applicable specification on the W3C site). (Previous versions of HTML weren’t so formalised as to have a DTD. Later versions of XHTML were moving towards schema. HTML 5 is being defined in such a way as to not have an official machine readable specification, but I think there may be third party schemas out there).
Find the definition of the body element:
Expand the references (
%body;in this example).That will give you a list of the elements that may be children of the body element.
Then just subtract that list of a list of all elements in that version of HTML and you will have the elements that either must be children of an element other than the body or are the root element (
<html>).