snipt

Ctrl+h for KB shortcuts

JavaScript

Disable Enter Key in jQuery

1
2
3
4
5
$(document).ready(function(){
	$('#targetId').keypress(function (event){  
		return event.keyCode == 13 ? false : true; 
	});
});
https://snipt.net/embed/44990ac84e727909a5cfff1bfd97fa94/
/raw/44990ac84e727909a5cfff1bfd97fa94/
44990ac84e727909a5cfff1bfd97fa94
js
JavaScript
5
2019-08-20T10:25:17
True
False
False
/api/public/snipt/9182/
disable-enter-key-in-jquery
<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><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#targetId&#39;</span><span class="p">).</span><span class="nx">keypress</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">event</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nx">event</span><span class="p">.</span><span class="nx">keyCode</span> <span class="o">==</span> <span class="mi">13</span> <span class="o">?</span> <span class="kc">false</span> <span class="o">:</span> <span class="kc">true</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>
disable, enter, jquery, key