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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts

    JS replace function

    Hi all,
    I am trying to implement a function whereby the user selects some text and on click of a button a set of span tags are wrapped around that selected text. If the text contains within it another set of tags(for example a href) it will surround the text with span tags aswell.


    <p> I went to the market yesterday to buy some <a href="url">fruit and vegetables</a> and then walked home instead catching the car </p> <p> The next day I did the same thing </p>

    So if the user selects from "I went to the" to "The next day" it would look something like this:

    <p><span color = 'blue'> I went to the market yesterday to buy some </span> <a href="url"><span color = 'blue'>fruit and vegetables</span></a><span color = 'blue'> and then walked home instead catching the car<span> </p> <p><span color = 'blue'> The next day </span color=blue> I did the same thing </p>


    Any idea how I can do this?

    Thanks

    Kind regards

    Chris

  • #2
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>document.selection 的 createRange</title>
    </head>
    <body>

    <div>please select me<div>
    <div><input type="button" value="makeBold" onclick="javascript:Bold();" /></div>
    <script type="text/javascript" language="javascript">
    <!--
    function Bold()
    {
    var r = document.selection.createRange();
    //use this object to get select area;
    r.execCommand("Bold");
    }
    -->
    </script>

    </body>
    </html>


  •  

    Posting Permissions

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