Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

jQuery. Steps in $.each()

1
2
3
4
5
6
var eachItem = 4; // someFunction() will work on 1st, 5th, 9th ... element
$('.selector').each(function(i) {
	if(i++ % eachItem === 0) { // to select 4th, 8th etc. elements use ++i instead of i++
		someFunction();
	}
});
https://snipt.net/embed/48ddd2a0e4e231a034ac64ebf3fde8ac/
https://snipt.net/raw/48ddd2a0e4e231a034ac64ebf3fde8ac/
48ddd2a0e4e231a034ac64ebf3fde8ac
js
JavaScript
6
2016-12-03T07:53:36
True
False
False
/api/public/snipt/129927/
jquery-steps-in-each
<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></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">eachItem</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span> <span class="c1">// someFunction() will work on 1st, 5th, 9th ... element</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.selector&#39;</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span><span class="p">(</span><span class="nx">i</span><span class="o">++</span> <span class="o">%</span> <span class="nx">eachItem</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// to select 4th, 8th etc. elements use ++i instead of i++</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">someFunction</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
each, function, hack, jquery

Text only

Iterate number in Jade

1
2
3
4
- for (var i = 1; i <= 14; ++i) {
.card
	img(src='img/presentations/blog/#{i}.jpg')
- }
https://snipt.net/embed/384393f571c262216676fc27f35f0ada/
https://snipt.net/raw/384393f571c262216676fc27f35f0ada/
384393f571c262216676fc27f35f0ada
text
Text only
4
2016-11-07T13:24:36
True
False
True
Dec 29, 2013 at 08:10 AM
/api/public/snipt/102889/
iterate-number-in-jade
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>- for (var i = 1; i &lt;= 14; ++i) { </span><span id="L-2"><a name="L-2"></a>.card </span><span id="L-3"><a name="L-3"></a> img(src=&#39;img/presentations/blog/#{i}.jpg&#39;) </span><span id="L-4"><a name="L-4"></a>- } </span></pre></div> </td></tr></table>
each, for, jade

Jade

Iterate 2 values with each in Jade

1
2
3
4
values = {"Word 1": "Apple", "Word 2": "IBM"};
ul
	each val, key in values
		li #{key}: #{val}
https://snipt.net/embed/9463f5a46b0f027472c2757bd333c770/
https://snipt.net/raw/9463f5a46b0f027472c2757bd333c770/
9463f5a46b0f027472c2757bd333c770
jade
Jade
4
2016-11-24T11:02:35
True
False
True
Nov 17, 2013 at 04:04 AM
/api/public/snipt/94638/
iterate-2-values-in-jade
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nt">values</span> = {&quot;Word 1&quot;: &quot;Apple&quot;, &quot;Word 2&quot;: &quot;IBM&quot;}; </span><span id="L-2"><a name="L-2"></a><span class="nt">ul</span> </span><span id="L-3"><a name="L-3"></a> <span class="nt">each</span> val, key in values </span><span id="L-4"><a name="L-4"></a> <span class="nt">li</span> <span class="si">#{</span><span class="n">key</span><span class="si">}</span>: <span class="si">#{</span><span class="k">val</span><span class="si">}</span> </span></pre></div> </td></tr></table>
each, jade

Jade

Iterate 1 value with each in Jade

1
2
3
4
5
ul
	items = ["Главная", "О нас", "Галерея", "Схема проезда", "Выезд", "Контакты"]
	each item, i in items
		li 
			a(href='#page-section#{i+1}') #{item}
https://snipt.net/embed/c17e62504b4a5f10495a882620138949/
https://snipt.net/raw/c17e62504b4a5f10495a882620138949/
c17e62504b4a5f10495a882620138949
jade
Jade
5
2016-11-09T01:40:10
True
False
True
Nov 17, 2013 at 03:57 AM
/api/public/snipt/94637/
iterate-values-in-jade
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nt">ul</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">items</span> = [&quot;Главная&quot;, &quot;О нас&quot;, &quot;Галерея&quot;, &quot;Схема проезда&quot;, &quot;Выезд&quot;, &quot;Контакты&quot;] </span><span id="L-3"><a name="L-3"></a> <span class="nt">each</span> item, i in items </span><span id="L-4"><a name="L-4"></a> <span class="nt">li</span> </span><span id="L-5"><a name="L-5"></a> <span class="nt">a</span>(<span class="na">href=</span><span class="s">&#39;#page-section#{i+1}&#39;</span>) <span class="si">#{</span><span class="n">item</span><span class="si">}</span> </span></pre></div> </td></tr></table>
each, jade
Copyrighted, illegal, or inappropriate content? Email [email protected].