contents

UK['kɒntents] US['kɒntents]

n. Content; content; theme (of a book, speech, program, etc.); the theme Content (plural noun of content); content (of books, etc.), directory; capacity, content; theme (of books, speeches, programs, etc.)

jquery contents() method syntax

Function: contents() method obtains the child nodes of each element in the matching element collection, including text and comment nodes.

Syntax: .contents()

Description: Given a jQuery object that represents a collection of DOM elements, the .contents() method allows us Retrieve the direct child nodes of these elements in the DOM tree and construct a new jQuery object with the matching elements. The .contents() and .children() methods are similar, except that the former includes text nodes and HTML elements in the resulting jQuery object. The .contents() method can also be used to obtain the content document of an iframe, provided that the iframe is on the same domain as the main page.

jquery contents() method example

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<p>Hello <a href="//m.sbmmt.com/">Apple</a>, how are you doing?</p>
<script>$("p").contents().filter(function(){ return this.nodeType != 1; }).wrap("<b/>");</script>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance