JQuery Selector parent

From CoderLearner
Jump to: navigation, search

Description

Select the parent of the child.

Syntax

$('element').parent()

Note

$.parent() is different from $(":parent").

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <script>
         $().ready(function() {
            $('ul').parent().css('background-color','green');
         });
      </script>
   </head>
   <body> 
      <div class="tte">
         <ul>
            <li>Great</li>
            <li>Powerful</li>
            <li>Super</li>
         </ul>
         <div class="fruit">
            <p>Apple,Banana,Coconut
            </p>
         </div>
      </div>
   </body>
</html>

Try It