.wrapAll()


.wrapAll( wrappingElement )Возвращает: jQuery

Описание: Функция помещает заданное содержимое вокруг выбранных элементов (как бы "обертывая" их).

  • Добавлен в версии: 1.2.wrapAll( wrappingElement )

    • wrappingElement
      Тип: Selector or htmlString or Element or jQuery
      A selector, element, HTML string, or jQuery object specifying the structure to wrap around the matched elements.
  • Добавлен в версии: 1.4.wrapAll( function )

    • function
      Тип: Function() => String or jQuery
      A callback function returning the HTML content or jQuery object to wrap around all the matched elements. Within the function, this refers to the first element in the set. Prior to jQuery 3.0, the callback was incorrectly called for every element in the set and received the index position of the element in the set as an argument.

The .wrapAll() function can take any string or object that could be passed to the $() function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. The structure will be wrapped around all of the elements in the set of matched elements, as a single group.

Consider the following HTML:

1
2
3
4
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>

Using .wrapAll(), we can insert an HTML structure around the inner <div> elements like so:

1
$( ".inner" ).wrapAll( "<div class='new' />");

The new <div> element is created on the fly and added to the DOM. The result is a new <div> wrapped around all matched elements:

1
2
3
4
5
6
<div class="container">
<div class="new">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
</div>

Примеры использования