snipt

Ctrl+h for KB shortcuts

JavaScript

Odd/Even rows with jQuery

$('div:odd').css('background-color', 'red');
https://snipt.net/embed/158517e172144a626028a556b268bb2a/
https://snipt.net/raw/158517e172144a626028a556b268bb2a/
158517e172144a626028a556b268bb2a
js
JavaScript
2
2016-09-29T18:00:11
True
False
False
Jun 17, 2013 at 02:59 AM
/api/public/snipt/42260/
odd-even-rows-with-jquery
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;div:odd&#39;</span><span class="p">).</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;background-color&#39;</span><span class="p">,</span> <span class="s1">&#39;red&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
jquery, odd/even, rows, zebra

PHP

odd/even rows with php

1
2
3
4
5
6
<ul>
    <?php foreach ($items as $item) :?>
		<li class="<?php print $oddeven ? 'odd' : 'even'; $oddeven = !$oddeven; ?>">			
		</li>
    <?php endforeach; ?>
</ul>
https://snipt.net/embed/902c4cb3e029ac931d5452ce08665dd7/
https://snipt.net/raw/902c4cb3e029ac931d5452ce08665dd7/
902c4cb3e029ac931d5452ce08665dd7
php
PHP
6
2016-09-25T15:40:59
True
False
False
/api/public/snipt/42259/
oddeven-rows-with-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">&lt;ul&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">foreach</span> <span class="p">(</span><span class="nv">$items</span> <span class="k">as</span> <span class="nv">$item</span><span class="p">)</span> <span class="o">:</span><span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-3"><a name="L-3"></a><span class="x"> &lt;li class=&quot;</span><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$oddeven</span> <span class="o">?</span> <span class="s1">&#39;odd&#39;</span> <span class="o">:</span> <span class="s1">&#39;even&#39;</span><span class="p">;</span> <span class="nv">$oddeven</span> <span class="o">=</span> <span class="o">!</span><span class="nv">$oddeven</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x">&quot;&gt; </span> </span><span id="L-4"><a name="L-4"></a><span class="x"> &lt;/li&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">endforeach</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-6"><a name="L-6"></a><span class="x">&lt;/ul&gt;</span> </span></pre></div> </td></tr></table>
odd/even, php, rows, zebra
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.