jQuery - offsetParent (), méthode

La description

le offsetParent() La méthode renvoie le parent positionné (par exemple relatif, absolu) du premier élément sélectionné.

Syntaxe

Voici la syntaxe simple pour utiliser cette méthode -

selector.offsetParent()

Paramètres

Voici la description de tous les paramètres utilisés par cette méthode -

  • NA

Exemple

Voici un exemple simple montrant l'utilisation de cette méthode.

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function(){
            $("p").offsetParent().addClass('hilight');
         });
      </script>
		
      <style>
         .hilight { background:yellow; }
      </style>
   </head>
	
   <body>
      <scan>Top Element</scan>
      <div style = "position:relative;">
         <div>sibling<div>child</div></div>
         <p>sibling</p>
         <scan>sibling</scan>
      <div>
   </body>
</html>

Cela produira le résultat suivant -

Exemple

Voici un exemple simple montrant l'utilisation de cette méthode.

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function(){
            $("p").offsetParent().addClass('hilight');
         });
      </script>
		
      <style>
         .hilight { background:yellow; }
      </style>
   </head>
		
   <body>
      <scan>Top Element</scan>
      <div class = "hilight" style = "position:relative;">
         <div>sibling<div>child</div></div>
         <p>sibling</p>
         <scan>sibling</scan>
      <div>
   </body>
</html>

Cela produira le résultat suivant -

jquery-traversing.htm