snipt

Ctrl+h for KB shortcuts

JavaScript

console exception

1
2
3
4
5
6
7
if ( typeof console === 'undefined') {
	var console = {
		log: function() {return},
		warn: function() {return},
		error: function() {return},
	}
}
https://snipt.net/embed/da6c06eef4651fe341bc5dd44aece841/
/raw/da6c06eef4651fe341bc5dd44aece841/
da6c06eef4651fe341bc5dd44aece841
js
JavaScript
7
2019-06-12T05:06:17
True
False
False
/api/public/snipt/10970/
console-exception
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="p">(</span> <span class="k">typeof</span> <span class="nx">console</span> <span class="o">===</span> <span class="s1">&#39;undefined&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">console</span> <span class="o">=</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">log</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span><span class="p">},</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">warn</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span><span class="p">},</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">error</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span><span class="p">},</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
console

JavaScript

jQuery version

jQuery.fn.jquery
https://snipt.net/embed/8ef01b8d08c6f5f5713055a957ad057f/
/raw/8ef01b8d08c6f5f5713055a957ad057f/
8ef01b8d08c6f5f5713055a957ad057f
js
JavaScript
1
2019-06-06T14:56:03
True
False
False
/api/public/snipt/10181/
jquery-version
<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></span><span id="L-1"><a name="L-1"></a><span class="nx">jQuery</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">jquery</span> </span></pre></div> </td></tr></table>
jquery

JavaScript

create qtip tooltip of data stored in object's 'info' namespace

1
2
3
4
5
6
7
$.fn.dataQtip = function() {
	var $dat = $(this).data('info');
	var review = '' ;
	for (key in $dat) 
		review += key + ': ' + $dat[key] + '<br />';
	$(this).qtip({content: review});
}
https://snipt.net/embed/0c802f59b5442f1c0c9736c5e801cbdd/
/raw/0c802f59b5442f1c0c9736c5e801cbdd/
0c802f59b5442f1c0c9736c5e801cbdd
js
JavaScript
7
2019-06-09T17:58:21
True
False
False
/api/public/snipt/7625/
create-qtip-tooltip-of-data-stored-in-objects-info-namespace
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">dataQtip</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">$dat</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">data</span><span class="p">(</span><span class="s1">&#39;info&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">var</span> <span class="nx">review</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span> <span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">for</span> <span class="p">(</span><span class="nx">key</span> <span class="k">in</span> <span class="nx">$dat</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">review</span> <span class="o">+=</span> <span class="nx">key</span> <span class="o">+</span> <span class="s1">&#39;: &#39;</span> <span class="o">+</span> <span class="nx">$dat</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;&lt;br /&gt;&#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">qtip</span><span class="p">({</span><span class="nx">content</span><span class="o">:</span> <span class="nx">review</span><span class="p">});</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
data, jquery, qtip, tooltip

JavaScript

scroll to element with jQuery

1
2
3
4
5
6
function scrollGo() {
   var x = $(this).offset().top - 100; // 100 provides buffer in viewport
   $('html,body').animate({scrollTop: x}, 500);
}
// set focus event on element
$('#myForm :input').focus(scrollGo); 
https://snipt.net/embed/c95e32050ff7e981ab98d22e2581547a/
/raw/c95e32050ff7e981ab98d22e2581547a/
c95e32050ff7e981ab98d22e2581547a
js
JavaScript
6
2019-06-15T05:45:02
True
False
False
/api/public/snipt/7396/
scroll-to-element-with-jquery
<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">function</span> <span class="nx">scrollGo</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">x</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span> <span class="o">-</span> <span class="mi">100</span><span class="p">;</span> <span class="c1">// 100 provides buffer in viewport</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;html,body&#39;</span><span class="p">).</span><span class="nx">animate</span><span class="p">({</span><span class="nx">scrollTop</span><span class="o">:</span> <span class="nx">x</span><span class="p">},</span> <span class="mi">500</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="c1">// set focus event on element</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#myForm :input&#39;</span><span class="p">).</span><span class="nx">focus</span><span class="p">(</span><span class="nx">scrollGo</span><span class="p">);</span> </span></pre></div> </td></tr></table>
jquery, scroll

CSS

rotate text in all browsers

1
2
3
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
https://snipt.net/embed/f86641b446fa188099c2acde3e3ebeb5/
/raw/f86641b446fa188099c2acde3e3ebeb5/
f86641b446fa188099c2acde3e3ebeb5
css
CSS
3
2019-06-13T19:56:11
True
False
False
/api/public/snipt/7319/
rotate-text-in-all-browsers
<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="nt">-webkit-transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">-90deg</span><span class="o">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">-moz-transform</span><span class="o">:</span> <span class="nt">rotate</span><span class="o">(</span><span class="nt">-90deg</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nt">filter</span><span class="o">:</span> <span class="nt">progid</span><span class="nd">:DXImageTransform</span><span class="nc">.Microsoft.BasicImage</span><span class="o">(</span><span class="nt">rotation</span><span class="o">=</span><span class="nt">3</span><span class="o">);</span> </span></pre></div> </td></tr></table>
css, rotate, text

JavaScript

hide/show FAQs in <dl>

$('dd').toggle();
$('dt').click(function() {$(this).next('dd').toggle('slideDown');});
https://snipt.net/embed/5e412c1bc3e0140ac4bfaae4fec128d4/
/raw/5e412c1bc3e0140ac4bfaae4fec128d4/
5e412c1bc3e0140ac4bfaae4fec128d4
js
JavaScript
2
2019-06-13T02:39:57
True
False
False
/api/public/snipt/7087/
hideshow-faqs-in-dl
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;dd&#39;</span><span class="p">).</span><span class="nx">toggle</span><span class="p">();</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;dt&#39;</span><span class="p">).</span><span class="nx">click</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">next</span><span class="p">(</span><span class="s1">&#39;dd&#39;</span><span class="p">).</span><span class="nx">toggle</span><span class="p">(</span><span class="s1">&#39;slideDown&#39;</span><span class="p">);});</span> </span></pre></div> </td></tr></table>
jquery, list, toggle