SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: replace text

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace text

    In this code:
    HTML Code:
    <td>
          "blank.png"
          <br>
          <a class="sample" href="javascript:void(0);" onclick="some function">Rename</a>
    </td>
    I am trying to change "blank.png" to "checker.jpg" without altering anything else in the td field. Below is what I have tried. I can load the contents of the TD tag into the tdText variable, but I can't change the value I need to change. Any Ideas where I am going wrong?

    Code:
    OldName = "blank.png"
    NewName = "checker.jpg"
    $(".imageRename").click(function () {
         tdText = $(sample).parent().html();
         tdText.replace(OldName, NewName);
         $(sample).parent().html(tdText);
            
    });

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,002
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    You could do it like this:

    HTML Code:
    <!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>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Replace example</title>
        <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
      </head>
      
      <body>
        <table width="960" border="0">
          <tr>
            <td id="replace">"blank.png"<br><a class="sample" href="javascript:void(0);" onclick="some function">Rename</a></td>
            <td>&nbsp;</td>
          </tr>
        </table>
        
        <script>
          $(document).ready(function() {
            OldName = "blank.png";
            NewName = "checker.jpg";
            tdText = $("#replace");
            tdText.html(tdText.html().replace(OldName, NewName));
          });
        </script>
      </body>
    </html>
    In this case I've given the table cell an id, but there are a number of ways to get a reference to it, depending on your mark-up.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect ... Thanks Pullo


Bookmarks

Posting Permissions

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