1

When I insert a div into a p element, the DOM will correct that to

<p></p>
<div></div>

Same for a figure element. It can't be a child of p. So called flow elements are only allowed into parents that allow flow elements.

How do I check with JavaScript if a node is a flow element, or an element that allows flow elements as children?

Update This has nothing to do with CSS. This is not about style, it's about the DOM. A div can have a div as a child, but a p cannot have a p as a child.

Jared Smith
  • 19,721
  • 5
  • 45
  • 83
Janghou
  • 1,613
  • 1
  • 21
  • 30

2 Answers2

0

I think there's not something like that but what you can do is implement your method

for example that's is snapshot from p element

p​
 tagName: "P"
 nodeName: "P"

You will find those attr if you console.log(p) which is the element , so you can implement a method that go through the document and check the element or for parts you needs

With specified array to decide if it's flow or not for example [p, figure, ...] and check if in the array then return that is flow

mooga
  • 3,136
  • 4
  • 23
  • 38
0

You probably can get the display style of an element to detect if the element is flow or phrasing.

window.getComputedStyle(element).display === 'block'
shtse8
  • 1,092
  • 12
  • 20