snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#101065

JavaScript

Exists

1
2
3
4
5
// if element exists
if($('selector').length){ //do something }

// if element does not exist
if(!$('selector').length){ //do something }
https://snipt.net/embed/76ea19e0605b3f01c0912bbbe9a8a870/
https://snipt.net/raw/76ea19e0605b3f01c0912bbbe9a8a870/
76ea19e0605b3f01c0912bbbe9a8a870
js
JavaScript
6
2014-04-20T17:33:13
True
False
Dec 17, 2013 at 11:11 AM
/api/public/snipt/101065/
exists
<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 id="L-1"><a name="L-1"></a><span class="c1">// if element exists</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;selector&#39;</span><span class="p">).</span><span class="nx">length</span><span class="p">){</span> <span class="c1">//do something }</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">// if element does not exist</span> </span><span id="L-5"><a name="L-5"></a><span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;selector&#39;</span><span class="p">).</span><span class="nx">length</span><span class="p">){</span> <span class="c1">//do something }</span> </span></pre></div> </td></tr></table>
jQuery
#20139

SQL

Header for SQL programs (views, functions, sps...)

1
2
3
4
5
6
7
8
-- =============================================
-- Author:      <Author Name>
-- Create date: <Creation date>
-- Description:	<Description>
-- Example:     <Example code to execute>
-- History:     <Modification date> > <Description of the modification>
--              <Modification date> > <Description of the modification>
-- =============================================
https://snipt.net/embed/6f59e9d050c1bca009023870251fa9ce/
https://snipt.net/raw/6f59e9d050c1bca009023870251fa9ce/
6f59e9d050c1bca009023870251fa9ce
sql
SQL
8
2014-04-17T14:50:49
True
False
/api/public/snipt/20139/
header-of-sql-programs
<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 id="L-1"><a name="L-1"></a><span class="c1">-- =============================================</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">-- Author: &lt;Author Name&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">-- Create date: &lt;Creation date&gt;</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">-- Description: &lt;Description&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="c1">-- Example: &lt;Example code to execute&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="c1">-- History: &lt;Modification date&gt; &gt; &lt;Description of the modification&gt;</span> </span><span id="L-7"><a name="L-7"></a><span class="c1">-- &lt;Modification date&gt; &gt; &lt;Description of the modification&gt;</span> </span><span id="L-8"><a name="L-8"></a><span class="c1">-- =============================================</span> </span></pre></div> </td></tr></table>
header, sql
#7998

C#

DateTime in format YYYYMMDD as String

DateTimeVariable.ToString("yyyyMMdd")
https://snipt.net/embed/7f488663e385be08ea36a24a5f5e8de5/
https://snipt.net/raw/7f488663e385be08ea36a24a5f5e8de5/
7f488663e385be08ea36a24a5f5e8de5
csharp
C#
1
2014-04-16T11:45:17
True
False
/api/public/snipt/7998/
fecha-en-formato-string-yyyymmdd-1
<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="n">DateTimeVariable</span><span class="p">.</span><span class="n">ToString</span><span class="p">(</span><span class="s">&quot;yyyyMMdd&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
c#, date
#7284

SQL

Date in format YYYYMMDD as String

SELECT CONVERT ( VarChar(8), GETDATE(), 112)
https://snipt.net/embed/0ee1c3f61df7b4d3fc208f605aa099b1/
https://snipt.net/raw/0ee1c3f61df7b4d3fc208f605aa099b1/
0ee1c3f61df7b4d3fc208f605aa099b1
sql
SQL
2
2014-04-17T19:57:13
True
False
/api/public/snipt/7284/
fecha-en-formato-string-yyyymmdd
<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="k">SELECT</span> <span class="k">CONVERT</span> <span class="p">(</span> <span class="nb">VarChar</span><span class="p">(</span><span class="mi">8</span><span class="p">),</span> <span class="n">GETDATE</span><span class="p">(),</span> <span class="mi">112</span><span class="p">)</span> </span></pre></div> </td></tr></table>
getdate, sql
#7223

SQL

GetDate without time

SELECT CAST ( FLOOR ( CAST ( GETDATE() AS DECIMAL (12, 5) ) ) AS DATETIME )
https://snipt.net/embed/ff4066ac4c56841a257535ac322b398b/
https://snipt.net/raw/ff4066ac4c56841a257535ac322b398b/
ff4066ac4c56841a257535ac322b398b
sql
SQL
1
2014-04-10T20:54:27
True
False
/api/public/snipt/7223/
getdate-sin-la-hora
<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="k">SELECT</span> <span class="k">CAST</span> <span class="p">(</span> <span class="n">FLOOR</span> <span class="p">(</span> <span class="k">CAST</span> <span class="p">(</span> <span class="n">GETDATE</span><span class="p">()</span> <span class="k">AS</span> <span class="nb">DECIMAL</span> <span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="p">)</span> <span class="p">)</span> <span class="k">AS</span> <span class="n">DATETIME</span> <span class="p">)</span> </span></pre></div> </td></tr></table>
getdate, sql
#7130

CSS

Campaña contra IE6

1
2
3
4
/* IE6 */
#usuarios-ie {background: #F8FFB9;color:#000; border-bottom: 2px solid #e2e3e2; text-align:center}
#usuarios-ie p {margin: 0; padding: 5px 0; line-height: 1.5em;font-size:0.7em;}
#usuarios-ie a {text-decoration: underline; font-weight: bold; color: #e300a6;}
https://snipt.net/embed/fc96ecf88deabd00c80dceacef9fd4d3/
https://snipt.net/raw/fc96ecf88deabd00c80dceacef9fd4d3/
fc96ecf88deabd00c80dceacef9fd4d3
css
CSS
5
2014-04-16T15:20:13
True
False
/api/public/snipt/7130/
campana-contra-ie6-1
<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 id="L-1"><a name="L-1"></a><span class="c">/* IE6 */</span> </span><span id="L-2"><a name="L-2"></a><span class="nf">#usuarios-ie</span> <span class="p">{</span><span class="k">background</span><span class="o">:</span> <span class="m">#F8FFB9</span><span class="p">;</span><span class="k">color</span><span class="o">:</span><span class="m">#000</span><span class="p">;</span> <span class="k">border-bottom</span><span class="o">:</span> <span class="m">2px</span> <span class="k">solid</span> <span class="m">#e2e3e2</span><span class="p">;</span> <span class="k">text-align</span><span class="o">:</span><span class="k">center</span><span class="p">}</span> </span><span id="L-3"><a name="L-3"></a><span class="nf">#usuarios-ie</span> <span class="nt">p</span> <span class="p">{</span><span class="k">margin</span><span class="o">:</span> <span class="m">0</span><span class="p">;</span> <span class="k">padding</span><span class="o">:</span> <span class="m">5px</span> <span class="m">0</span><span class="p">;</span> <span class="k">line-height</span><span class="o">:</span> <span class="m">1.5em</span><span class="p">;</span><span class="k">font-size</span><span class="o">:</span><span class="m">0.7em</span><span class="p">;}</span> </span><span id="L-4"><a name="L-4"></a><span class="nf">#usuarios-ie</span> <span class="nt">a</span> <span class="p">{</span><span class="k">text-decoration</span><span class="o">:</span> <span class="k">underline</span><span class="p">;</span> <span class="k">font-weight</span><span class="o">:</span> <span class="k">bold</span><span class="p">;</span> <span class="k">color</span><span class="o">:</span> <span class="m">#e300a6</span><span class="p">;}</span> </span></pre></div> </td></tr></table>
ie6
#7129

HTML

Campaña contra IE6

1
2
3
4
5
6
<!--[if IE 6]>
<div id="usuarios-ie">
	<p><strong>¿Sabías que nos estás visitando con <span class="resaltado">Internet Explorer 6.0</span> un navegador ya obsoleto?</strong><br>
	Actualízate a <a href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx">una versión más reciente</a> o prueba otro navegador como <a href="http://www.mozilla.com" title="Firefox web browser">Firefox</a>, <a href="http://www.opera.com/" title="Opera Browser">Opera</a>, <a href="http://www.apple.com/safari/" title="Apple Safari">Safari</a> o <a href="http://www.google.com/chrome" title="Google Chrome">Chrome</a>.</p>
</div>
<![endif]-->
https://snipt.net/embed/696c05466f3a9f0ff5b56db09af6f74f/
https://snipt.net/raw/696c05466f3a9f0ff5b56db09af6f74f/
696c05466f3a9f0ff5b56db09af6f74f
html
HTML
7
2014-04-10T20:53:35
True
False
/api/public/snipt/7129/
campana-contra-ie6
<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="c">&lt;!--[if IE 6]&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="c">&lt;div id=&quot;usuarios-ie&quot;&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="c"> &lt;p&gt;&lt;strong&gt;¿Sabías que nos estás visitando con &lt;span class=&quot;resaltado&quot;&gt;Internet Explorer 6.0&lt;/span&gt; un navegador ya obsoleto?&lt;/strong&gt;&lt;br&gt;</span> </span><span id="L-4"><a name="L-4"></a><span class="c"> Actualízate a &lt;a href=&quot;http://www.microsoft.com/windows/products/winfamily/ie/default.mspx&quot;&gt;una versión más reciente&lt;/a&gt; o prueba otro navegador como &lt;a href=&quot;http://www.mozilla.com&quot; title=&quot;Firefox web browser&quot;&gt;Firefox&lt;/a&gt;, &lt;a href=&quot;http://www.opera.com/&quot; title=&quot;Opera Browser&quot;&gt;Opera&lt;/a&gt;, &lt;a href=&quot;http://www.apple.com/safari/&quot; title=&quot;Apple Safari&quot;&gt;Safari&lt;/a&gt; o &lt;a href=&quot;http://www.google.com/chrome&quot; title=&quot;Google Chrome&quot;&gt;Chrome&lt;/a&gt;.&lt;/p&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="c">&lt;/div&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="c">&lt;![endif]--&gt;</span> </span></pre></div> </td></tr></table>
ie6