What is the difference between open and closed shadow DOM encapsulation mode?

∥☆過路亽.° 提交于 2019-11-28 23:24:34

With the open mode you can access the Shadow DOM via the shadowRoot property of the HTML element.

With the closed mode you cannot. shadowRoot will return null.

You can use both modes for you want to achieve.

Here is a detailed explanation of the differences.

To add to the accepted answer. The closed mode of Shadow DOM has the single benefit which is to provide Web Component authors with the flexibility to decide how (if at all) to expose the Shadow Root of the component. However, it's incredibly easy to circumvent any efforts a component author makes at hiding the Shadow Root so it's probably not worth bothering. See Open vs. Closed Shadow DOM for a more detailed explanation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!