jQuery Ctrl Enter in Textarea
Learn how jQuery Check Ctrl Enter in Textarea
Published
- jQuery Ctrl Enter in Textarea
- Ctrl Enter in Textarea Example #1
- Ctrl Enter in Textarea Example #1 Using Mac
- Ctrl Enter in Textarea Example #2
jQuery Ctrl Enter in Textarea
You can use the event.ctrlKey flag to see if the Ctrl key is pressed, something like this:
Example-1
$('#textareaId').keydown(function (e) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey)P{
// Ctrl-Enter pressed
}
});
Example-1 work Using MAC
$('#textareaId').keydown(function (e) {
if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
// do something
}
});
Example-2 using JavaScript
<textarea id="content1" cols="30" rows="10"></textarea>
<p id="result"></p>
<script>
let content1 = document.querySelector('#content1');
content1.addEventListener('click', logKey);
function logKey(event) {
result.textContent = 'The ctrl key is pressed: '+event.ctrlKey;
}
</script>