Using jQuery with shadow dom

后端 未结 1 1425
一整个雨季
一整个雨季 2021-01-07 01:18

Here I have created elements with shadow dom.

/* some preparing code */
this.createShadowRoot();  // creates shadow root, this refers to element
相关标签:
1条回答
  • 2021-01-07 01:46

    This might be a problem with jQuery 2.1.1.

    Using jQuery 2.1.3 in jsfiddle seems to solve this problem:

    https://jsfiddle.net/bnh74s87/

    document.addEventListener("DOMContentLoaded",function(){
      var div=document.getElementById("dTest");
      var shadow=div.createShadowRoot();
      shadow.innerHTML='<p>Hi!</p>';
      document.body.appendChild(document.createTextNode(shadow.childNodes.length));
      console.log(shadow.querySelectorAll("p"));
      console.log($("p",shadow));
      $("p",shadow).html("Hello!");
    },false);
    <script src="https://code.jquery.com/jquery-2.1.3.js"></script>
    <div id="dTest"></div>

    0 讨论(0)
提交回复
热议问题