加载中...

:root1.9+


概述    root selector

返回值:jQuery

描述:选择该文档的根元素。

  • V : 1.9jQuery( ":root" )

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

示例

设置<html>背景颜色为黄色

  1. $(":root").css("background-color","yellow");

实例

显示根元素的标签名。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>root demo</title>
  6. <style>
  7. span.fot {
  8. color: red;
  9. font-size: 120%;
  10. font-style: italic;
  11. }
  12. </style>
  13. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  14. </head>
  15. <body>
  16. <div id="log">The root of this document is: </div>
  17. <script>
  18. $( "<b></b>" ).html( $( ":root" )[ 0 ].nodeName ).appendTo( "#log" );
  19. </script>
  20. </body>
  21. </html>

运行一下


还没有评论.