wyc
wyc

Reputation: 55273

Avoiding creation of strings in contenteditable area

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:

enter image description here

Is there any way to avoid them? Via jQuery or something?

Upvotes: 2

Views: 49

Answers (1)

Brian Hadaway
Brian Hadaway

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

Related Questions