I\'m attempting to check whether or not a contenteditable div has focus, but I\'m having some trouble. Here\'s my code so far:
if ($(\"#journal-content:focus\")
Try:
if ($("#journal-content").is(":focus")) {
alert("Has Focus");
} else {
alert("Doesn't Have Focus");
}
Or:
window.contenteditable_focused = false;
$("#journal-content").focus(function() {
//alert("Has Focus");
contenteditable_focused = true;
});
$("#journal-content").blur(function() {
//alert("Doesn't Have Focus");
contenteditable_focused = false;
});
Check for contenteditable_focused
before executing your script.
Or:
if ($( document.activeElement ).is("#journal-content")) {
alert("Has Focus");
} else {
alert("Doesn't Have Focus");
}