• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • :root

    选择该文档的根元素。

    jQuery(":root")

    在HTML中,文档的根元素,和$(":root")选择的元素一样,永远是<html>元素。

    例子

    显示根元素的标签名。

    <!DOCTYPE html>
    <html>
    <head>
      <style>
    span.fot { color: red; font-size: 120%; font-style: italic; }
      </style>
      <script src="https://www.lanmper.cn/static/js/jquery-3.5.0.js"></script>
    </head>
    <body>
      <div id="log">The root of this document is: </div>
    <script>
    $( "<b></b>" ).html( $( ":root" )[0].nodeName ).appendTo( "#log" );
    </script>
     
    </body>
    </html>
    

    上篇::header

    下篇::lang(language)