snipt

Ctrl+h for KB shortcuts

JavaScript

jQuery poistion among siblings

1
2
3
4
5
6
7
$('div').click(function() {
    // Will give you the index out of just the DIV tags
    var index = $(this).parent().find('> ' + this.tagName).index(this);

    // Will give you the index out of all siblings
    var index = $(this).parent().find('> *').index(this);
});
https://snipt.net/embed/c1bfdf3e7eb89e6717e92b1cb4aaa6af/
/raw/c1bfdf3e7eb89e6717e92b1cb4aaa6af/
c1bfdf3e7eb89e6717e92b1cb4aaa6af
js
JavaScript
7
2019-06-18T11:17:44
True
False
False
/api/public/snipt/5483/
jquery-poistion-among-siblings
<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></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;div&#39;</span><span class="p">).</span><span class="nx">click</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="c1">// Will give you the index out of just the DIV tags</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">var</span> <span class="nx">index</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">parent</span><span class="p">().</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;&gt; &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">tagName</span><span class="p">).</span><span class="nx">index</span><span class="p">(</span><span class="k">this</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="c1">// Will give you the index out of all siblings</span> </span><span id="L-6"><a name="L-6"></a> <span class="kd">var</span> <span class="nx">index</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">parent</span><span class="p">().</span><span class="nx">find</span><span class="p">(</span><span class="s1">&#39;&gt; *&#39;</span><span class="p">).</span><span class="nx">index</span><span class="p">(</span><span class="k">this</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
"jonathan sharp", "next to", dom, index, jquery, number, place, position

JavaScript

Jquery. Adding onClick event for serveral classes

1
2
3
4
5
$(document).ready(function() {
    $(".redeem,.change_expiry_date").click(function(){
         $("#operation").attr("value",this.name);
    });
});
https://snipt.net/embed/e11b56df85bd67805cdfc14c4f83e2a5/
/raw/e11b56df85bd67805cdfc14c4f83e2a5/
e11b56df85bd67805cdfc14c4f83e2a5
js
JavaScript
5
2019-06-18T12:10:09
True
False
False
/api/public/snipt/4342/
adding-onclick-event-for-serveral-classes
<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="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 class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.redeem,.change_expiry_date&quot;</span><span class="p">).</span><span class="nx">click</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;#operation&quot;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&quot;value&quot;</span><span class="p">,</span><span class="k">this</span><span class="p">.</span><span class="nx">name</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>
attr, click, jquery

JavaScript

Add class depending on browser.

1
2
3
$(document).ready(function(){
    $('html').addClass($.browser);
});
https://snipt.net/embed/05377847e9d76683b7765e7bf10d1ba9/
/raw/05377847e9d76683b7765e7bf10d1ba9/
05377847e9d76683b7765e7bf10d1ba9
js
JavaScript
3
2019-06-13T22:15:27
True
False
False
/api/public/snipt/4310/
add-class-depending-on-browser
<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></span><span id="L-1"><a name="L-1"></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-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;html&#39;</span><span class="p">).</span><span class="nx">addClass</span><span class="p">(</span><span class="nx">$</span><span class="p">.</span><span class="nx">browser</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>
css, javascript, jquery