I'm struggling to determine if a contenteditable div has focus with my current code. Here is what I have so far:
if ($("#journal-content:focus")) {
alert("Has Focus");
} else {
alert("Doesn't Have Focus");
}
The issue I'm encountering is that it always displays "Has focus" even when it shouldn't. What is the most effective approach to resolve this?
Update: I am trying to identify the cursor location in the contenteditable div prior to inserting a new element. If the user last clicked in the header, when I replace the selection and add a new element using Rangy, it remains in the header. Therefore, I need a method to determine if the contenteditable div has focus/the cursor to ensure I insert the element at the end if it doesn't.
Update 2: Check out this JSFiddle to see the problem illustrated: http://jsfiddle.net/2NHrM/