snipt

Ctrl+h for KB shortcuts

JavaScript

replace A HREF to SPAN

1
2
3
$('.head-recall').each(function () {
	$(this).replaceWith('<span>' + $(this).html() + '</span>');
});
https://snipt.net/embed/365826b2618249f8163f4b9d7bef8984/
https://snipt.net/raw/365826b2618249f8163f4b9d7bef8984/
365826b2618249f8163f4b9d7bef8984
js
JavaScript
3
2016-02-10T01:31:17
True
False
Apr 02, 2014 at 09:26 AM
/api/public/snipt/126750/
replace-a-href-to-span
<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 id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.head-recall&#39;</span><span class="p">).</span><span class="nx">each</span><span class="p">(</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="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">replaceWith</span><span class="p">(</span><span class="s1">&#39;&lt;span&gt;&#39;</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">html</span><span class="p">()</span> <span class="o">+</span> <span class="s1">&#39;&lt;/span&gt;&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
javascript, js

JavaScript

Test if href points image

1
2
3
4
if($(this).attr('href').indexOf('.jpg') > 0) // or any other extension
{
    //do what you want
}
https://snipt.net/embed/6b6e76de0f8d48d7e980f025b5f0f153/
https://snipt.net/raw/6b6e76de0f8d48d7e980f025b5f0f153/
6b6e76de0f8d48d7e980f025b5f0f153
js
JavaScript
4
2016-02-09T01:26:06
True
False
Mar 17, 2014 at 01:11 PM
/api/public/snipt/122560/
test-if-href-points-image
<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="k">if</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">attr</span><span class="p">(</span><span class="s1">&#39;href&#39;</span><span class="p">).</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;.jpg&#39;</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1">// or any other extension</span> </span><span id="L-2"><a name="L-2"></a><span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">//do what you want</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
check, href, image, img, javascript, jpeg, jpg, jquery, js, test
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.