jQuery contents( ) Method

« Previous Chapter Next Chapter »

Description:

The contents( ) method finds all the child nodes inside the matched elements (including text nodes), or the content document, if the element is an iframe.

Syntax:

Here is the simple syntax to use this method:

Example

selector.contents( )
                                        

Parameters:

Here is the description of all the parameters used by this method:

  • NA

Example:

Try the following example which shows how you can access the objects in an iframe from a parent window. This operation has become possible just because of contents() method.

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.js"></script>
<script>
  $(document).ready(function(){
    var $content = $("iframe").contents();
    $content.find("body").append("I'm in an iframe!");
  });
  </script>
  
</head>
<body>
  <iframe src="/jquery/index.html" width="300" height="100">
  </iframe>
</body>
</html>
                                        
Code It Online

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!