0

I need to remove the last instance of

>

from:

<b>
<a href="link">Home</a> &gt;
<a href="link">Category</a> &gt;
<a href="link">Sub-category</a> &gt;
<a href="link">Sub-sub-category</a> &gt;
</b>

I assume regex will need to be employed, but I haven't found any good ways to do it. I'm removing the last instance of the link with

(a:last).remove();

but, after a couple iterations, I get multiple > > > in a row with no links between

4 Answers4

2

How about a solution in CSS instead of javascript?

CSS

.link {
    display: inline-block;
}

.link:after {
    content: ' \003e';
}

.link:last-of-type:after {
    content: '';
}

HTML

<div class="link"> <a href="#">Crumb 1</a> </div>
<div class="link"> <a href="#">Crumb 2</a> </div>
<div class="link"> <a href="#">Crumb 3</a> </div>

see http://jsfiddle.net/stackolee/tzbDe/

stakolee
  • 893
  • 1
  • 7
  • 20
  • It's a nice solution. I think it's slightly more elegant (and shorter) to use `
  • ` instead of a div with a class, like in this exameple: http://stackoverflow.com/a/5362995/1535827
  • – Strille Dec 13 '13 at 18:26