Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Event invitation response note

Please use the Yes, Maybe, or No links in the event body in order to send your response to the event organizer.  Controls in your email application will not properly notify the organizer.  Thank you!
https://snipt.net/embed/bd0a1175f9950de5baff4eb02a9f7d92/
https://snipt.net/raw/bd0a1175f9950de5baff4eb02a9f7d92/
bd0a1175f9950de5baff4eb02a9f7d92
text
Text only
1
2016-12-05T00:42:06
True
False
False
Jan 04, 2016 at 04:50 PM
/api/public/snipt/103076/
event-invitation-response-note
<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>Please use the Yes, Maybe, or No links in the event body in order to send your response to the event organizer. Controls in your email application will not properly notify the organizer. Thank you! </span></pre></div> </td></tr></table>
event, invitation, response

JavaScript

Event Trigger When User Scrolls To Element jQuery

1
2
3
4
5
6
7
8
var target = $('p').offset().top;

var interval = setInterval(function() {
    if ($(window).scrollTop() >= target) {
        alert('here it is!');
        clearInterval(interval);
    }
}, 200);
https://snipt.net/embed/bc7fa157a67a27f709fd4ed6ba3e8d44/
https://snipt.net/raw/bc7fa157a67a27f709fd4ed6ba3e8d44/
bc7fa157a67a27f709fd4ed6ba3e8d44
js
JavaScript
8
2016-12-07T06:35:27
True
False
False
Jan 28, 2013 at 10:43 AM
/api/public/snipt/54643/
event-trigger-when-user-scrolls-to-element-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> <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">target</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;p&#39;</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">interval</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="nb">window</span><span class="p">).</span><span class="nx">scrollTop</span><span class="p">()</span> <span class="o">&gt;=</span> <span class="nx">target</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;here it is!&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">clearInterval</span><span class="p">(</span><span class="nx">interval</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="p">},</span> <span class="mi">200</span><span class="p">);</span> </span></pre></div> </td></tr></table>
event, javascript, jquery, trigger

Text only

jQuery : Event on a checkbox called twice

1
2
3
4
5
That's because when you bind a click event on a label with a "for" attribute it triggers the event twice :
 - One on the label
 - One on the checkbox
 
The selector should be bound to the checkbox, not the label to be triggered only once
https://snipt.net/embed/ee33427ba4f6a5dba3e0d10d073175b7/
https://snipt.net/raw/ee33427ba4f6a5dba3e0d10d073175b7/
ee33427ba4f6a5dba3e0d10d073175b7
text
Text only
6
2016-12-04T02:33:27
True
False
True
Oct 29, 2012 at 04:37 AM
/api/public/snipt/46589/
jquery-event-on-a-checkbox-called-twice
<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>That&#39;s because when you bind a click event on a label with a &quot;for&quot; attribute it triggers the event twice : </span><span id="L-2"><a name="L-2"></a> - One on the label </span><span id="L-3"><a name="L-3"></a> - One on the checkbox </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>The selector should be bound to the checkbox, not the label to be triggered only once </span></pre></div> </td></tr></table>
event, jQuery

JavaScript

DABUG - Event - DOMNodeInserted

1
2
3
4
  $(document).bind('DOMNodeInserted', function(event) {
    console.log('inserted ' + event.target.nodeName + // new node
              ' in ' + event.relatedNode.nodeName); // parent
  });
https://snipt.net/embed/372bb567ecd2a4bc5548fbd48791d418/
https://snipt.net/raw/372bb567ecd2a4bc5548fbd48791d418/
372bb567ecd2a4bc5548fbd48791d418
js
JavaScript
5
2016-11-01T22:49:09
True
False
True
Jun 28, 2012 at 04:54 AM
/api/public/snipt/43118/
event-domnodeinserted
<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="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;DOMNodeInserted&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;inserted &#39;</span> <span class="o">+</span> <span class="nx">event</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">nodeName</span> <span class="o">+</span> <span class="c1">// new node</span> </span><span id="L-3"><a name="L-3"></a> <span class="s1">&#39; in &#39;</span> <span class="o">+</span> <span class="nx">event</span><span class="p">.</span><span class="nx">relatedNode</span><span class="p">.</span><span class="nx">nodeName</span><span class="p">);</span> <span class="c1">// parent</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">});</span> </span></pre></div> </td></tr></table>
dabug, event, javascript

JavaScript

Onload event listener

1
2
3
4
5
6
7
if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', init, false);
} else if (typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', init, false);
} else if (typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', init);
}
https://snipt.net/embed/23f5ba8b074548b23ea6691c82fefd9b/
https://snipt.net/raw/23f5ba8b074548b23ea6691c82fefd9b/
23f5ba8b074548b23ea6691c82fefd9b
js
JavaScript
7
2016-12-07T04:28:32
True
False
False
/api/public/snipt/38798/
onload-event-listener
<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="nb">window</span><span class="p">.</span><span class="nx">addEventListener</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="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">&#39;load&#39;</span><span class="p">,</span> <span class="nx">init</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s1">&#39;load&#39;</span><span class="p">,</span> <span class="nx">init</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nb">window</span><span class="p">.</span><span class="nx">attachEvent</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-6"><a name="L-6"></a> <span class="nb">window</span><span class="p">.</span><span class="nx">attachEvent</span><span class="p">(</span><span class="s1">&#39;onload&#39;</span><span class="p">,</span> <span class="nx">init</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>
event, listener
Copyrighted, illegal, or inappropriate content? Email [email protected].