snipt

Ctrl+h for KB shortcuts

JavaScript

Foldable text with headings (jQuery)

1
2
3
4
5
6
var $posttext = $('.post-text');
$posttext.find('h1').nextUntil('h1').hide();
$posttext.find('h1:first').nextUntil('h1').show();
$posttext.find('h1').on('click', function() { 
	$(this).nextUntil('h1').slideToggle(400);
});
https://snipt.net/embed/a0b9c109d617a9a49120c5744c25e1a6/
/raw/a0b9c109d617a9a49120c5744c25e1a6/
a0b9c109d617a9a49120c5744c25e1a6
js
JavaScript
6
2016-12-21T03:41:24
True
False
True
Aug 06, 2013 at 08:08 PM
/api/public/snipt/72403/
foldable-text-with-headings-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">var</span> <span class="nx">$posttext</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.post-text&#39;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$posttext</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;h1&#39;</span><span class="p">).</span><span class="nx">nextUntil</span><span class="p">(</span><span class="s1">&#39;h1&#39;</span><span class="p">).</span><span class="nx">hide</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">$posttext</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;h1:first&#39;</span><span class="p">).</span><span class="nx">nextUntil</span><span class="p">(</span><span class="s1">&#39;h1&#39;</span><span class="p">).</span><span class="nx">show</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">$posttext</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;h1&#39;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;click&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">nextUntil</span><span class="p">(</span><span class="s1">&#39;h1&#39;</span><span class="p">).</span><span class="nx">slideToggle</span><span class="p">(</span><span class="mi">400</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
javascript, jquery

PHP

Load jQuery from Google CDN on Wordpress

1
2
3
4
5
6
7
8
function jquery_cdn() {
   if (!is_admin()) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3');
      wp_enqueue_script('jquery');
   }
}
add_action('init', 'jquery_cdn');
https://snipt.net/embed/1812127ed64a523ea15b42170b5248ae/
/raw/1812127ed64a523ea15b42170b5248ae/
1812127ed64a523ea15b42170b5248ae
php
PHP
8
2016-11-27T00:41:43
True
False
True
Mar 05, 2013 at 09:26 AM
/api/public/snipt/57037/
load-jquery-from-google-cdn-on-wordpress
<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="x">function jquery_cdn() {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> if (!is_admin()) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> wp_deregister_script(&#39;jquery&#39;);</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> wp_register_script(&#39;jquery&#39;, &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#39;, false, &#39;1.8.3&#39;);</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> wp_enqueue_script(&#39;jquery&#39;);</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> }</span> </span><span id="L-7"><a name="L-7"></a><span class="x">}</span> </span><span id="L-8"><a name="L-8"></a><span class="x">add_action(&#39;init&#39;, &#39;jquery_cdn&#39;);</span> </span></pre></div> </td></tr></table>
cdn, functions.php, javascript, jquery, php, wordpress

JavaScript

Target IE10 with jQuery

1
2
3
4
//Detect IE10 and set an appropriate <html> class, considering that IE10 doesn't have conditional classes
if (/*@[email protected]*/false && document.documentMode === 10) {
    document.documentElement.className+=' ie-10';
}
https://snipt.net/embed/1c3e25e7e89355c0fcb858ac4deb06b9/
/raw/1c3e25e7e89355c0fcb858ac4deb06b9/
1c3e25e7e89355c0fcb858ac4deb06b9
js
JavaScript
4
2016-12-10T10:58:59
True
False
True
Mar 05, 2013 at 08:28 AM
/api/public/snipt/57032/
target-ie10-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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//Detect IE10 and set an appropriate &lt;html&gt; class, considering that IE10 doesn&#39;t have conditional classes</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="p">(</span><span class="cm">/*@[email protected]*/</span><span class="kc">false</span> <span class="o">&amp;&amp;</span> <span class="nb">document</span><span class="p">.</span><span class="nx">documentMode</span> <span class="o">===</span> <span class="mi">10</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">document</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">.</span><span class="nx">className</span><span class="o">+=</span><span class="s1">&#39; ie-10&#39;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"internet explorer", browser, css, ie10, javascript, jquery

JavaScript

Remove class after delay in jQuery

1
2
3
4
5
var link = $('#link');
link.addClass('current');
setTimeout(function() {
	link.removeClass('current');
}, 3000);
https://snipt.net/embed/7e42432eb9e1b1c95955270e5df94f79/
/raw/7e42432eb9e1b1c95955270e5df94f79/
7e42432eb9e1b1c95955270e5df94f79
js
JavaScript
5
2016-11-12T02:02:46
True
False
True
Feb 28, 2013 at 05:16 AM
/api/public/snipt/56693/
remove-class-after-delay-in-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></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">link</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#link&#39;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">link</span><span class="p">.</span><span class="nx">addClass</span><span class="p">(</span><span class="s1">&#39;current&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">setTimeout</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="nx">link</span><span class="p">.</span><span class="nx">removeClass</span><span class="p">(</span><span class="s1">&#39;current&#39;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="p">},</span> <span class="mi">3000</span><span class="p">);</span> </span></pre></div> </td></tr></table>
class, delay, javascript, jquery