javascript - Why does my preventDefault not work in Chrome browser jquery? -


look @ code, if used chrome, notice preventdefault doesn't work when press enter key, works in firefox , safari, why?

var fighting_textarea=$('#fighting');  			  			fighting_textarea.on( "keydown", function( event ) {  				if ( event.which == 13 ) {  				    event.preventdefault();  					alert('hello');  				}  				  			});//click  	  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea id="fighting"> </textarea>

it working fine, have remove alert(i guess not required). 1 more thing should consider code 10 too, b'coz on iphone safari gives code 10.

var fighting_textarea=$('#fighting');  			  			fighting_textarea.on( "keydown", function( event ) {  				if ( event.keycode == 10 || event.keycode == 13 ) {  				    event.preventdefault();  					  				}  				  			});//click  	  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea id="fighting"> </textarea>


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -