Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

20 September 2009

Wrap Long URLs with jQuery

This doesn't seem to exist on the internet, so I wrote it. It's not super great, but does the job.

$(document).ready(function () {
  $("a").each(function () {
    var t = $(this).text();
    if(t.length > 30) {
      $(this).text(t.replace(/\./g,". ").replace(/\//g, "/ "));
    }
  });
});

Comments

  1. Thanks for the tip. It was really helpful. I wanted to wrap the long URL names in a Drupal block view. I slightly modified your code according to my requirements.

    $(“div.view-review-docs”).find(“a”).each(function () {

    var t = $(this).text();
    if(t.length > 40) {
    

    var str1=$(this).text();
    var str2=”n”;
    str1 = str1.substr(0,35) + str2 + str1.substr(35);

    $(this).text(str1);

    }
    

    });;

    Ajinkya Kulkarni / 6:29am / 14 January 2011

Leave a comment

Markdown

0.079 seconds