You might also want to take a look at my Fancy First Letter plugin:

http://plugins.learningjquery.com/fancyletter/

--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Jun 10, 2008, at 6:47 PM, Hamish Campbell wrote:


Nothing wrong with regex. Note that the expression you have will catch
all Caps and Numbers - so something like "Go Here" will have the G and
H in the spans.

A better pattern might be /^([A-Za-z0-9])/g -- this will match the
first character of the link, but only if it is a sensible character
(ie, alphanumeric).

ie:

$(document).ready(function() {
  $("#Nav li a").each(function() {
     var text = $(this).html();
     $(this).html(text.replace(/^([A-Za-z0-9])/g,'<span class="caps">
$1</span>'));
  });
});

If you really don't want regex, you could do this:

$(document).ready(function() {
  $("#Nav li a").each(function() {
     var text = $(this).html();
     var first = $('<span>'+text.charAt(0)+'</
span>').addClass('caps');
     $(this).html(text.substring(1)).prepend(first);
  });
});


On Jun 11, 8:00 am, 703designs <[EMAIL PROTECTED]> wrote:
Here's what I've come up with based on one response in this Mailing
List, although I think that it's a bit messy. I have a natural regex
aversion...

$(document).ready(function() {
        $("#Nav li a").each(function() {
                var text = $(this).html();
$(this).html(text.replace(/([A-Z0-9])/g,'<span class="caps">$1</
span>'));
        });

});

On Jun 10, 3:39 pm, 703designs <[EMAIL PROTECTED]> wrote:



I want to add a class to the first letter of every link in a page's
navigation. Here's what I have now, but I'm missing a way to actually
grab the first letter. This script would add the "caps" class to the
whole link, and I only need the letter. The reason for this is that
the links are using "font-variant: small-caps", and it doesn't make
letters that are actually capitalized large enough to be noticeably
different from their small-caps counterparts.

$(document).ready(function() {
        $("#nav li a").each(function() {
                this.addClass("caps");
        });

});- Hide quoted text -

- Show quoted text -

Reply via email to