Add style to siblings : siblings « jQuery « JavaScript Tutorial






<html>
  <head>
    <script type='text/javascript' src='js/jquery-1.3.2.js'></script>
    <script type='text/javascript'>
var tmpExample = {
  ready : function() {
    $('ul#tmpPlaces li.myStyle').siblings().addClass('tmpSiblings');
  }
};

$(document).ready(tmpExample.ready);
    </script>
    <style type='text/css'>
body {
    font: 16px sans-serif;
}
h4 {
    font-size: 16px;
    margin: 0 0 5px 0;
}
ul#tmpPlaces {
    list-style: none;
    margin: 0;
    padding: 0;
}
ul#tmpPlaces li {
    margin: 1px;
    padding: 3px;
}
li.tmpSiblings{
    background: khaki;
}
    </style>
  </head>
  <body>
    <ul id='tmpPlaces'>
      <li>a</li>
      <li>b</li>
      <li>c</li>
      <li>d</li>
      <li>e</li>
      <li>f</li>
      <li class='myStyle'>g</li>
    </ul>
  </body>
</html>








30.96.siblings
30.96.1.Get siblings
30.96.2.Find all siblings with a class "selected" of each div.
30.96.3.Add style to siblings
30.96.4.Sibling by class name