Reputation: 55273
I'm using this pludgin: http://jakiestfu.github.io/Medium.js/docs/ to improve my contenteditable area, and stuff like this to populate it when clicking on a link:
$("#input-content").html(content);
The problem is that sometimes when the cursor is at the beginning of the div it creates strings like this:
Is there any way to avoid them? Via jQuery or something?
Upvotes: 2
Views: 49
Reputation: 1893
You could check for any text nodes (nodeType === 3)
then wrap those nodes with the appropriate HTML tag as such:
function wrapText(){ $('#yourDiv').contents().filter( function(){ return this.nodeType === 3; }).wrap('<p/>');
}
Then call wrapText
on blur
.
Upvotes: 1