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

154
Views
¿Cómo alternar etiquetas en cursiva dentro de div editable?

tratando de crear un editor html simple
en el siguiente ejemplo, coloque el cursor dentro de la palabra lorem y haga clic en el botón
la palabra se pone en cursiva
Dos preguntas

  • ¿Es esta la manera correcta de hacer esto?
  • ¿Cómo alternar esta funcionalidad, es decir, eliminar <i></i> haciendo clic de nuevo?

 var ed = $('#ed'); $('.btnitalic').on('click', function(){ var sel = window.getSelection(); sel.modify('move', 'backward', 'word'); sel.modify('extend', 'right', 'word'); var str = sel.toString(); var rn = sel.getRangeAt(0); var tx = rn.extractContents(); var i = document.createElement('i'); i.appendChild(tx); rn.insertNode(i); console.clear(); console.log(ed.html()); });
 .ed{display:inline-block; width:100%; min-height:99px; background:orange;}
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button class='btnitalic'>ITALIC</button> <br><br> <div class='ed' id='ed' contenteditable> lorem ipsum dolor sit </div>

about 4 years ago · Santiago Gelvez
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!