When you make an element (in my div case) contenteditable = "true", when inserting a line, a <div> inserted. But if the cursor stood for example in <p> then <p></p> inserted, which triples me more. Following the example of CREDITOR, when clicked, if the field is empty, <p><br></p> inserted. But the cursor still stands at nothing and inserts a div when translating a line. And here is how to make the cursor now fall into this <p> so that the divas are not stamped?

Although the question is not correct. How to make a line break inserted <p> instead of the standard <div> ?

    3 answers 3

    The difference between <div> and <p> can be corrected by styles ...

     *[contenteditable] div, *[contenteditable] p { margin: 1em 0em 1em 0em; } 
    • Well, this is quite a crutch. I'm still more interested in javascript - the solution. But thanks anyway :) - Dimka

    Try using <p contenteditable></p> instead of div ...

    • Sorry again divas. - Dimka
    • It will be even worse. - Qwertiy

    And what if, after editing, we replace all the <div> tags with <p> ?

    • No, we must immediately :)) - Dimka