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

243
Views
¿Cómo puedo truncar una cadena en jQuery?

Tengo títulos largos y quiero truncarlos pero de manera que no se rompan las palabras, quiero decir que el corte ocurre entre palabras y no corta una palabra.

¿Cómo puedo hacerlo usando jquery?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

De: truncamiento de texto jQuery (leer más estilo)

Prueba esto:

 var title = "This is your title"; var shortText = jQuery.trim(title).substring(0, 10) .split(" ").slice(0, -1).join(" ") + "...";
  • Probado aquí

Y también puedes usar un complemento:

  • Complemento expansor de jQuery

Como una extensión de String

 String.prototype.trimToLength = function(m) { return (this.length > m) ? jQuery.trim(this).substring(0, m).split(" ").slice(0, -1).join(" ") + "..." : this; };

Usar como

 "This is your title".trimToLength(10);
over 4 years ago · Santiago Trujillo Report

0

La solución anterior no funcionará si la cadena original no tiene espacios.

Prueba esto:

 var title = "This is your title"; var shortText = jQuery.trim(title).substring(0, 10) .trim(this) + "...";
over 4 years ago · Santiago Trujillo Report

0

 function truncateString(str, length) { return str.length > length ? str.substring(0, length - 3) + '...' : str }
over 4 years ago · Santiago Trujillo 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!