Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
on pressing enter in contenteditable its copying line style/title to next line

I have simple contententeditable div

<div contenteditable="true">
  <p>
    Line 1 <span title="action">action</span>
  </p>
</div>

If the user click at the end of line 1 and press enter, then start typing. The next line also copies the same span's background. How to avoid it? see demo: https://jsfiddle.net/89z5d2r0/1/

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can add a non-breaking space or &nbsp after the span tag to circumvent this behavior. See the snippet below:

div {
  width: 200px;
  height: 200px;
  border: 1px solid #f1f2f3;
}

p span {
  background: #ccc;
}
<div contenteditable="true">
  <p>
    Line 1 <span title="action">action</span>&nbsp
  </p>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

Because there is no text in the p tag and that's why text starts from the span tag. That's why text is written in a span tag with it's properties. At least add &nbsp after span tag.

div {
  width: 200px;
  height: 200px;
  border: 1px solid #f1f2f3;
}
p span {
  background: #ccc;
}
<div contenteditable="true">
  <p>
    Line 1 <span title="action">action</span>&nbsp
  </p>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!