English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery contents() Method

jQuery Traversal Methods

The contents() method finds all child nodes within the selected element (including text nodes).

If the iframe is in the same domain, the content() method can also be used to get the content document of the iframe.

The content() method is similar tochildren()This method also returns text and comment nodes.

Syntax:

$.selector.contents()

Example

Find all text nodes within the <p> element and wrap them in a <b> element:

$("button").click(function(){
  $("p").contents().wrap("<b></b>);
});
Test and See‹/›

jQuery Traversal Methods