Odd Even mal einfach

Wie man mit jQuery jedes zweite Element (Odd / Even) erkennen kann

JavaScript


jQuery.noConflict();
jQuery(document).ready(function($){
  $("#ulList li:nth-child(even).item").css("background", "#eeeeee");
});

HTML Code


<ul id="ulList">
<li class="item">LI-Element 1</li>
<li class="item">LI-Element 2</li>
<li class="item">LI-Element 3</li>
<li class="item">LI-Element 4</li>
<li class="item">LI-Element 5</li>
<li class="item">LI-Element 6</li>
<li class="item">LI-Element 7</li>
<li class="item">LI-Element 8</li>
<li class="item">LI-Element 9</li>
</ul>

Demo

  • LI-Element 1
  • LI-Element 2
  • LI-Element 3
  • LI-Element 4
  • LI-Element 5
  • LI-Element 6
  • LI-Element 7
  • LI-Element 8
  • LI-Element 9

Links zu diesem Thema