Which DOM elements can be child of tr?

后端 未结 4 1587
遥遥无期
遥遥无期 2020-11-30 14:57

I have problem becouse I want to surround some of td inside tr so I need to know.

Which DOM elements can be child of tr? (I know div<

4条回答
  •  感动是毒
    2020-11-30 15:34

    If the question is about a DOM tree constructed from an HTML document that conforms to HTML specifications, then the answer is td and th, as explained in paxdiablo’s answer.

    But you can modify a DOM tree as you like, in scripting. For example:

    
    
    foo bar

    This will make a div element a child of a tr element. You could even put create some td elements and make them children of the div element.

    Whether this makes sense and whether it might confuse browsers is a different issue. And browsers will not parse normally HTML markup where e.g. tr element contains a div element as a child – parsers are not prepared to handle such cases. Grouping td elements (in any other way than making them children of a tr) is not possible in HTML markup. But in the DOM, you can create odd trees.

    If just want to deal with some td elements in a special way, give them a class.

提交回复
热议问题