I’m writing a function to parse words inline in a contenteditable div and replace tags (@…, #…) with an anchor tag. I was firing it on the keyup event, and it worked perfectly. The problem was that I wanted to replace tags not only after the user hits space, but also after they hit a non-word character. Since the keyup event only gets access to the key pressed, not the actual character entered, I couldn’t recognize punctuation marks.
All I did was change to the keypress event, and now my function leaves off the last character of the tag when creating the anchor. Here is my code: http://jsfiddle.net/jwoah12/CcwSt/115/.
wordStart and wordEnd seem to have correct values, but j.toString() produces the wrong result.
Thanks,
Jared
Try the following:
On keypress, get the character entered, save it in a variable.
On keyup, look at the value in the variable, if it’s the punctuation you are looking for, execute your replacement logic.