Spec-Zone.ru › jQuery

:root Селектор

селектор корня

Описание: Выбирает элемент, являющийся корнем документа.

  • версия добавлена: 1.9jQuery( ":root" )

В HTML корень документа, и, следовательно, элемент, который $(":root") выбирает, всегда является элементом <html>.

Пример:

Отобразить имя тега корневого элемента.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>root demo</title>
  <style>
  span.fot {
    color: red;
    font-size: 120%;
    font-style: italic;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.7.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>

Демо:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/root-selector

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API