Element.part - Web APIs 编辑
The part
property of the Element
interface represents the part identifier(s) of the element (i.e. set using the part
attribute), returned as a DOMTokenList
. These can be used to style parts of a shadow DOM, via the ::part
pseudo-element.
Syntax
let elementPartList = element.part
Examples
The following excerpt is from our shadow-part example. Here the part
attribute is used to find the shadow parts, and the part
property is then used to change the part identifiers of each tab so the correct styling is applied to the active tab when tabs are clicked.
let tabs = [];
let children = this.shadowRoot.children;
for(let elem of children) {
if(elem.getAttribute('part')) {
tabs.push(elem);
}
}
tabs.forEach((tab) => {
tab.addEventListener('click', (e) => {
tabs.forEach((tab) => {
tab.part = 'tab';
})
e.target.part = 'tab active';
})
console.log(tab.part);
})
Specifications
Specification | Status | Comment |
---|---|---|
Shadow Parts The definition of 'Element.part' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论