snipt

Ctrl+h for KB shortcuts

JavaScript

jquery if exists DOM element

1
2
3
4
5
if ( $('#myDiv').length ) {

  //do something

}
https://snipt.net/embed/cf1dbea1e1b6f0baa01c2301f1824d97/
https://snipt.net/raw/cf1dbea1e1b6f0baa01c2301f1824d97/
cf1dbea1e1b6f0baa01c2301f1824d97
js
JavaScript
5
2016-09-29T18:25:17
True
False
False
/api/public/snipt/33933/
jquery-if-exists-dom-element
<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 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="s1">&#39;#myDiv&#39;</span><span class="p">).</span><span class="nx">length</span> <span class="p">)</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="c1">//do something</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
dom, jquery

JavaScript

Highlight all div elements on page

javascript:var%20eL=document.getElementsByTagName('div');for(i=0;i%3CeL.length;i++)%7Bvoid(eL%5Bi%5D.style.border='solid%201px%20red')%7D
https://snipt.net/embed/421403ebcd22826355affd469c29f583/
https://snipt.net/raw/421403ebcd22826355affd469c29f583/
421403ebcd22826355affd469c29f583
js
JavaScript
1
2016-09-28T18:31:55
True
False
False
/api/public/snipt/14513/
highlight-all-div-elements-on-page-using-a-specified-colour
<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 id="L-1"><a name="L-1"></a><span class="nx">javascript</span><span class="o">:</span><span class="kd">var</span><span class="o">%</span><span class="mi">20</span><span class="nx">eL</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s1">&#39;div&#39;</span><span class="p">);</span><span class="k">for</span><span class="p">(</span><span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="nx">i</span><span class="o">%</span><span class="mi">3</span><span class="nx">CeL</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span><span class="nx">i</span><span class="o">++</span><span class="p">)</span><span class="o">%</span><span class="mi">7</span><span class="nx">Bvoid</span><span class="p">(</span><span class="nx">eL</span><span class="o">%</span><span class="mi">5</span><span class="nx">Bi</span><span class="o">%</span><span class="mi">5</span><span class="nx">D</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">border</span><span class="o">=</span><span class="s1">&#39;solid%201px%20red&#39;</span><span class="p">)</span><span class="o">%</span><span class="mi">7</span><span class="nx">D</span> </span></pre></div> </td></tr></table>
bookmarklet, display, div, dom, element, favelet, highlight, javascript, js
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.