Jquery: remove the last letter

Hi,

I wonder how to remove the last letter inside an element,

This is the code I came out with so far, but I cannot get the last letter from the structure of my elements and text - have I done something wrong in my HTML structure??

var str = $("#tag ul").text();
var str = str.replace(/ /g, "");
var the_length=str.length;
var last = str.charAt(the_length-1);

This is the HTML,

<div id="tag" class="tag">
            
            <h2><span>Behold, the handy tag system:</span></h2>
            
            <ul>

			<a href="animation">animation</a> /
    		<a href="2-D">2-D</a> /
    		<a href="line-drawing">line-drawing</a> /
    		<a href="editorial">editorial</a> /
    		<a href="patterns">patterns</a> /
    		<a href="photomontage-floral">photomontage-floral</a> /
    		<a href="3-D">3-D</a> /
    		<a href="black-and-white">black-and-white</a> /
    		<a href="advertising">advertising</a> /
    		<a href="packaging">packaging</a> /
    		<a href="crests">crests</a> /
    		<a href="typography">typography</a> /
    		<a href="sketches">sketches</a> /
    		<a href="layered">layered</a> /
    		<a href="design">design</a> /
    		<a href="manga">manga</a> /
    		<a href="people">people</a> /
    		<a href="hand-lettered">hand-lettered</a> /
    		<a href="experimental">experimental</a> /
    		<a href="vector">vector</a>[COLOR="Red"] /[/COLOR]
    </ul>

I want to remove the last ‘/’ (red) in the tag.

this is the test site,

http://lauthiamkok.net/works/design/web/ginger_monkey_2010/

Many thanks,
L

You have invalid html. A <ul> tag can only have <li> tags as it’s direct children.

If you put each of those links in an li, then you could target the last li and then target it’s last character.

You really should just generate the output serverside without the trailing slash though so you don’t need to touch it up with javascript.

got it! thanks for the advice :smiley: