From what I've read about CodeMirror I should have onBlur
written to my Console Log when I Blur the textarea. Nothing gets echo'd.
var textarea = document.getElementById('block');
var editor = CodeMirror.fromTextArea(textarea, {
lineNumbers: false,
content: textarea.value,
onBlur: function () {
console.log("onBlur");
}
});
Have I missed anything out at all?
From what I've read about CodeMirror I should have onBlur
written to my Console Log when I Blur the textarea. Nothing gets echo'd.
var textarea = document.getElementById('block');
var editor = CodeMirror.fromTextArea(textarea, {
lineNumbers: false,
content: textarea.value,
onBlur: function () {
console.log("onBlur");
}
});
Have I missed anything out at all?
Share Improve this question edited Feb 9, 2018 at 14:22 Alexander 23.5k11 gold badges64 silver badges73 bronze badges asked Feb 26, 2013 at 16:24 ngplaygroundngplayground 21.6k37 gold badges98 silver badges174 bronze badges 1- 1 For anyone surfing Stack Overflow for answers on legacy builds, the onBlur function within the CodeMirror instance shown above is the correct method for older versions of CodeMirror. Newer versions use editor.on(). – Gagich Commented Feb 4, 2019 at 13:43
1 Answer
Reset to default 17Bind it using .on()
as described in the CodeMirror's Events documentation.
var textarea = document.getElementById('block');
var editor = CodeMirror.fromTextArea(textarea, {
lineNumbers: false,
content: textarea.value,
});
editor.on("blur", function(){
console.log("onBlur");
});