Shadow Dom (Shadowroot) Access

Source: Internet
Author: User
Tags gtx

Example

Gtx.shadowRoot.getElementById ("translation")

GTX as host object

Cause

Grab the contents of the chorome Google Translate docking rack. Content with information div ID is "bubble-content"

var Contend=document.getelementbyid ("Bubble-content")

Contend is NULL?!! How could it be null? I'm not spelling it wrong.

This is unscientific and then found that the DIV has a #shadow-root (open) in the outer layer

Something I've never seen before.

It's not always a demon, question 80% is right here.

After checking the relevant information, determine

In short, shadow-root the object under the parcel, not in the global Dom tree, so getElementById, and so on, gets the object in the package.

The purpose of this function is to separate out a block of rendering, not affected by the outer style, the inner layer of the style does not affect the display of the outer layers.

Access is as follows

1 Get the root node of the shadow-root outer layer This node is in the global DOM tree.

var Gtx=document.getelementbyid ("Gtx-host")

2 Get the Shadow block of the GTX

Gtx.shadowroot

After 3, you're free to do it again.

For example, take a node in a shadow block.

var Truecontent=gtx.shadowroot.getelementbyid ("translation");

Later think about, in fact, before vaguely seen this function, but because one really no use, forgotten

Shadow Dom (Shadowroot) Access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.