Enter empty divs and contenteditable = true?

Why doesn't the cursor enter some of my divs when contenteditable is allowed?

also, why does my browser tell me that there is nothing in the div when there is clearly a space in it ?!

var div = '<div> </div>'; 
div.innerHTML = undefined 

What gives?

0
source share
1 answer

contenteditable does not apply to empty elements, so you may need to insert a character without a break in the empty elements you want to edit

non-expanding space "&nbsp;"will act as a symbol if left alone,
while a space " "will be considered only a symbol if it is placed after another symbol

    <div>" "</div>----------------> innerHTML = undefined
    <div>"&nbsp;"</div>-------->innerHTML =  

&nbsp; html , " ", " "

var nbsp = "&nbsp;",
    div = document.getElementById('id');
div.innerHTML = nbsp

jquery

var div = $('div#id')
div.html(nbsp1)
-1

All Articles