snipt

Ctrl+h for KB shortcuts

JavaScript

a quick jQuery solution for stripping XHTML tags from a string, except for a specific tag

1
2
3
4
5
$('.sanitize').each(function() {
    $(this).html(
        $(this).html().replace(/\<\/?[^p ]{1,2}[^>]*>/ig,'')
    )
});
https://snipt.net/embed/ef6abc08bd74ef9c7f5970ac2da27b87/
/raw/ef6abc08bd74ef9c7f5970ac2da27b87/
ef6abc08bd74ef9c7f5970ac2da27b87
js
JavaScript
5
2019-08-22T11:50:10
True
False
False
/api/public/snipt/2343/
a-quick-jquery-solution-for-stripping-xhtml-tags-from-a-string-except-for-a-specific-tag
<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="nx">$</span><span class="p">(</span><span class="s1">&#39;.sanitize&#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">html</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="k">this</span><span class="p">).</span><span class="nx">html</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\&lt;\/?[^p ]{1,2}[^&gt;]*&gt;/ig</span><span class="p">,</span><span class="s1">&#39;&#39;</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="p">});</span> </span></pre></div> </td></tr></table>
jquery

JavaScript

jquery re-select previous object

1
2
3
4
$('#something')
    .css('display','block')
    .end()
    .html('bob')
https://snipt.net/embed/5bf126784ca69aff274414707a817a00/
/raw/5bf126784ca69aff274414707a817a00/
5bf126784ca69aff274414707a817a00
js
JavaScript
4
2019-08-22T11:50:25
True
False
False
/api/public/snipt/1844/
jquery-re-select-previous-object
<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="s1">&#39;#something&#39;</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a> <span class="p">.</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;display&#39;</span><span class="p">,</span><span class="s1">&#39;block&#39;</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a> <span class="p">.</span><span class="nx">end</span><span class="p">()</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">.</span><span class="nx">html</span><span class="p">(</span><span class="s1">&#39;bob&#39;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
jquery

JavaScript

grab selected option from select element

$('#selectList').val();
https://snipt.net/embed/ab9f23364ec4895ead234c065ad7466f/
/raw/ab9f23364ec4895ead234c065ad7466f/
ab9f23364ec4895ead234c065ad7466f
js
JavaScript
1
2019-08-19T13:10:23
True
False
False
/api/public/snipt/46/
grab-selected-option-from-select-element
<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">$</span><span class="p">(</span><span class="s1">&#39;#selectList&#39;</span><span class="p">).</span><span class="nx">val</span><span class="p">();</span> </span></pre></div> </td></tr></table>
javascript, jquery