Friday, 25 January 2013

siblings()

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">

     $(document).ready(function(){
       $("p").siblings('.selected').addClass("hilight");
     });

  </script>
  <style>
      .hilight { background:yellow; }
  </style>

</head>
<body>
  <div><span>Hello</span></div>
  <p class="selected">Hello Again</p>
  <p>And Again</p>
</body>
</html>
 
-----------------
 
3
4
5
6
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li class="third-item">list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
</ul>


$('li.third-item').siblings().css('background-color', 'red');
 
------------------------------
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div><span>Hello</span></div>
<p class="selected">Hello Again</p>
<p>And Again</p>
<script>$("p").siblings(".selected").css("background", "yellow");</script>
</body>
</html>
 
 

No comments:

Post a Comment