Thanks a lot Wizzud... works perfectly.

On Nov 12, 5:48 pm, Wizzud <[EMAIL PROTECTED]> wrote:
> eg.
>
> $('#links a').each(function(){
>     var me = $(this);
>     me.html( me.text().replace(/(^\w+)/,'<strong>$1</strong>') );
>   });
>
> or
>
> $('#links a').each(function(){
>     var me = $(this)
>        , t = me.text().split(' ');
>     me.html( '<strong>'+t.shift()+'</strong> '+t.join(' ') );
>   });
>
> etc
>
> On Nov 12, 9:17 pm, "Andy Matthews" <[EMAIL PROTECTED]> wrote:
>
> > Viktor...
>
> > You'd probably need an $.each() on there then.
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>
> > Behalf Of Viktor Tarm
> > Sent: Monday, November 12, 2007 2:35 PM
> > To: jQuery (English)
> > Subject: [jQuery] Re: How to make the first word bold.
>
> > Thank you all for your help.
>
> > Andy, I'm looking to bold the first WORD, of all the links, not the first
> > link.
>
> > Karl, I made a simple page to test your code. It looks like this:
>
> > <script type="text/javascript" src="./src/jquery-1.2.1.pack.js"></
> > script>
> > <script type="text/javascript">
> >         $(document).ready(function() {
> >                 var mystring = $('#links a').html();
> >                 var firstword =
> > mystring.replace(/(^\w+)/,'<strong>$1</strong>');
> >         $('#links a').html(firstword);
> >         });
> > </script>
>
> > </head>
> > <body>
>
> > <div id="links">
> >         <p class="title"><a href="a.html">one two three four five</a></p>
> >         <p class="title"><a href="b.html">six seven eight</a></p>
> >         <p class="title"><a href="c.html">nine ten eleven</a></p>
> >         <p class="title"><a href="d.html">twelve thirteen fourteen</a></p>
> > </div>
>
> > This results in changing the content to = the first link's content, like so:
>
> > <div id="links">
> >         <p class="title"><a href="a.html"><strong>One</strong> two three
> > four five</a></p>
> >         <p class="title"><a href="b.html"><strong>One</strong> two three
> > four five</a></p>
> >         <p class="title"><a href="c.html"><strong>One</strong> two three
> > four five</a></p>
> >         <p class="title"><a href="d.html"><strong>One</strong> two three
> > four five</a></p> </div>
>
> > I'm looking to just make the first word of the link bold (without changing
> > the content), like this:
>
> > <div id="links">
> >         <p class="title"><a href="a.html"><strong>One</strong> two three
> > four five</a></p>
> >         <p class="title"><a href="b.html"><strong>six</strong> seven eight</
> > a></p>
> >         <p class="title"><a href="c.html"><strong>nine</strong> ten elevan</
> > a></p>
> >         <p class="title"><a href="d.html"><strong>twelve</strong> thirteen
> > fourteen</a></p> </div>
>
> > Any ideas?
>
> > Thanks again.
>
> > On Nov 12, 12:24 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> > > You could also do this with a regular expression. Maybe something like
> > > this:
>
> > > var mystring = $('#title a:first').html(); var firstword =
> > > mystring.replace(/(^\w+)/,'<strong>$1</strong>');
> > > $('#title a:first').html(firstword);
>
> > > --Karl
> > > _________________
> > > Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> > > On Nov 12, 2007, at 11:52 AM, [EMAIL PROTECTED] wrote:
>
> > > > Somebody else probably has a more consice method but you could try
> > > > something like this
>
> > > > var mystring = "One Two Three"; //replace with your string var
> > > > stringarray = mystring.split(" "); var firstword = mystring.split("
> > > > ")[0]; myarray = jQuery.grep(stringarray, function(n, i){
> > > >       return (i > 0);
> > > > });
> > > > $("div#title a").append("<strong>" + firstword + "</strong>
> > > > ").append(myarray.join(" "));
>
> > > > On Nov 11, 8:56 pm, Viktor Tarm <[EMAIL PROTECTED]> wrote:
> > > >> I am trying to make the first word of a sentence (a title from a
> > > >> generated feed) bold.
>
> > > >> TURN THIS:
>
> > > >> <div id="title">
> > > >>         <a href="123.html">One Two Three</a> </div>
>
> > > >> INTO THIS:
>
> > > >> <div id="title">
> > > >>         <a href="123.html"><strong>One</strong> Two Three</a>
> > > >> </div>
>
> > > >> I sure there is a way to do with jQuery, but I can't quite figure
> > > >> it out. I have tried something like this, with no luck:
>
> > > >> $("#title.a").contents(0).wrap("<strong></strong>");
>
> > > >> Any help would be greatly appreciated.

Reply via email to