snipt

Ctrl+h for KB shortcuts

JavaScript

twitter text change

1
2
3
$('#twitter').bind('textchange', function (event, previousText) {
  $('#charactersLeft').html( 140 - parseInt($(this).val().length) );
});
https://snipt.net/embed/3dfec7d8c30699642d994102296ad5ef/
/raw/3dfec7d8c30699642d994102296ad5ef/
3dfec7d8c30699642d994102296ad5ef
js
JavaScript
3
2019-07-22T12:43:56
True
False
False
/api/public/snipt/15322/
twitter-text-change
<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="s1">&#39;#twitter&#39;</span><span class="p">).</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;textchange&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">event</span><span class="p">,</span> <span class="nx">previousText</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="s1">&#39;#charactersLeft&#39;</span><span class="p">).</span><span class="nx">html</span><span class="p">(</span> <span class="mi">140</span> <span class="o">-</span> <span class="nb">parseInt</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">val</span><span class="p">().</span><span class="nx">length</span><span class="p">)</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>
js