Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Match() String help

    Hi all!
    I need some help with this code:
    Code:
    <script>
    str = new String("Hello World")
    document.write(str.match('Hello').fontcolor("blue"))
    </script>
    I want the word "Hello" of the string to have a blue color. Not the hole string JUST the "Hello" word.
    Exp:
    PHP
    .NET

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    With the following CSS
    Code:
    .hello{
        color: blue;
    }
    you can write the script like this:
    Code:
    var
        str='Hello World';
    alert(str.replace(/Hello/g,'<span class="hello">$&</span>'));
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    How i do it if i have the "Hello" word in a textarea.
    Code:
    <textarea>
    Hello World
    </textarea>
    Help Please
    Exp:
    PHP
    .NET


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •