Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Load external content with jQuery

1
2
3
4
5
6
$("#content").load("somefile.html", function(response, status, xhr) {
  // error handling
  if(status == "error") {
    $("#content").html("An error occured: " + xhr.status + " " + xhr.statusText);
  }
});
https://snipt.net/embed/16f92a730870b63699d37aa8943b1538/
https://snipt.net/raw/16f92a730870b63699d37aa8943b1538/
16f92a730870b63699d37aa8943b1538
js
JavaScript
7
2016-11-30T08:01:05
True
False
False
/api/public/snipt/110254/
load-external-content-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="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">load</span><span class="p">(</span><span class="s2">&quot;somefile.html&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">response</span><span class="p">,</span> <span class="nx">status</span><span class="p">,</span> <span class="nx">xhr</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1">// error handling</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span><span class="p">(</span><span class="nx">status</span> <span class="o">==</span> <span class="s2">&quot;error&quot;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#content&quot;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span><span class="s2">&quot;An error occured: &quot;</span> <span class="o">+</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">status</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">statusText</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
external, javascript, jquery

JavaScript

external links new window

1
2
3
4
// external links new window
$(document).ready(function(){
 $("a[@href^='http']").attr('target','_blank');
});
https://snipt.net/embed/578b67fbb5fa70ee0f7da882d8259137/
https://snipt.net/raw/578b67fbb5fa70ee0f7da882d8259137/
578b67fbb5fa70ee0f7da882d8259137
js
JavaScript
4
2016-12-03T20:08:56
True
False
False
/api/public/snipt/33583/
external-links-new-window
<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">// external links new window</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;a[@href^=&#39;http&#39;]&quot;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;target&#39;</span><span class="p">,</span><span class="s1">&#39;_blank&#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>
"new window", external, jquery, links

CSS

css3 external links

1
2
3
4
/* add rel external to external links */
a:not([rel~="external"]) {
	text-decoration: none; border-bottom: dotted 1px;
}
https://snipt.net/embed/149331d959230d0c7781c777bab52474/
https://snipt.net/raw/149331d959230d0c7781c777bab52474/
149331d959230d0c7781c777bab52474
css
CSS
4
2016-12-03T11:18:01
True
False
False
/api/public/snipt/33582/
css3-external-links
<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="c">/* add rel external to external links */</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">a</span><span class="nd">:not</span><span class="o">([</span><span class="nt">rel</span><span class="o">~=</span><span class="s2">&quot;external&quot;</span><span class="o">])</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">text-decoration</span><span class="o">:</span> <span class="nb">none</span><span class="p">;</span> <span class="nb">border-bottom</span><span class="o">:</span> <span class="nb">dotted</span> <span class="m">1px</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>
css3, external, links
Copyrighted, illegal, or inappropriate content? Email [email protected].