Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Using length to truncate arrary

1
2
3
var foo = [1, 2, 3, 4, 5, 6];
foo.length = 3;
foo; // [1, 2, 3]
https://snipt.net/embed/97045465de6acb2481341d25e5854f3e/
https://snipt.net/raw/97045465de6acb2481341d25e5854f3e/
97045465de6acb2481341d25e5854f3e
js
JavaScript
3
2016-12-07T06:09:13
True
False
False
/api/public/snipt/35775/
using-length-to-truncate-arrary
<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></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">foo</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">];</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">foo</span><span class="p">.</span><span class="nx">length</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">foo</span><span class="p">;</span> <span class="c1">// [1, 2, 3]</span> </span></pre></div> </td></tr></table>
javascript, tips, tricks

JavaScript

Making Cross Browser Functions

1
2
3
4
5
6
7
8
 var getMyText = function(myDiv) {
    getMyText =
        myDiv.innerText !== undefined ? // innerText not supported in FF
       &nbsp;    function(myDiv) {return myDiv.innerText} :
            function(myDiv) {return myDiv.textContent};

    return getMyText(myDiv);
}
https://snipt.net/embed/24d1a45a338ec296f38e229cf1ccc8be/
https://snipt.net/raw/24d1a45a338ec296f38e229cf1ccc8be/
24d1a45a338ec296f38e229cf1ccc8be
js
JavaScript
8
2016-12-02T20:27:58
True
False
False
/api/public/snipt/35322/
making-cross-browser-functions
<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> <a href="#L-7">7</a> <a href="#L-8">8</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">getMyText</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">getMyText</span> <span class="o">=</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">innerText</span> <span class="o">!==</span> <span class="kc">undefined</span> <span class="o">?</span> <span class="c1">// innerText not supported in FF</span> </span><span id="L-4"><a name="L-4"></a> <span class="o">&amp;</span><span class="nx">nbsp</span><span class="p">;</span> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span><span class="k">return</span> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">innerText</span><span class="p">}</span> <span class="o">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="kd">function</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">)</span> <span class="p">{</span><span class="k">return</span> <span class="nx">myDiv</span><span class="p">.</span><span class="nx">textContent</span><span class="p">};</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nx">getMyText</span><span class="p">(</span><span class="nx">myDiv</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
javascript, tips, tricks

HTML

Browser/Engine specific styles

1
2
3
4
-moz-border-top: 5px
-webkit-border-top: 5px
-k8-border-top: 5px
-khtml-border-top: 5px
https://snipt.net/embed/a3c3510b5aa8d4392aa3eb84fc69fc2d/
https://snipt.net/raw/a3c3510b5aa8d4392aa3eb84fc69fc2d/
a3c3510b5aa8d4392aa3eb84fc69fc2d
html
HTML
4
2016-12-06T20:23:11
True
False
False
/api/public/snipt/10009/
browserengine-specific-styles
<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>-moz-border-top: 5px </span><span id="L-2"><a name="L-2"></a>-webkit-border-top: 5px </span><span id="L-3"><a name="L-3"></a>-k8-border-top: 5px </span><span id="L-4"><a name="L-4"></a>-khtml-border-top: 5px </span></pre></div> </td></tr></table>
browsers, hacks, ie, mozilla, safari, tricks

CSS

CSS Specificity

1
2
3
4
5
6
CSS SPECIFICITY___________________

Elements = 1 points
Classes = 10 points
Identifiers = 100 points
Inline Styling = 1000 points
https://snipt.net/embed/8ccf16f374bd43e5a1920f9ddeb0ac01/
https://snipt.net/raw/8ccf16f374bd43e5a1920f9ddeb0ac01/
8ccf16f374bd43e5a1920f9ddeb0ac01
css
CSS
6
2016-12-05T06:10:30
True
False
False
/api/public/snipt/8119/
css-specificity
<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="nt">CSS</span> <span class="nt">SPECIFICITY___________________</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nt">Elements</span> <span class="o">=</span> <span class="nt">1</span> <span class="nt">points</span> </span><span id="L-4"><a name="L-4"></a><span class="nt">Classes</span> <span class="o">=</span> <span class="nt">10</span> <span class="nt">points</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">Identifiers</span> <span class="o">=</span> <span class="nt">100</span> <span class="nt">points</span> </span><span id="L-6"><a name="L-6"></a><span class="nt">Inline</span> <span class="nt">Styling</span> <span class="o">=</span> <span class="nt">1000</span> <span class="nt">points</span> </span></pre></div> </td></tr></table>
css, selectors, tricks
Copyrighted, illegal, or inappropriate content? Email [email protected].