Replace Inline CSS Background:URL

View: New views
1 Messages — Rating Filter:   Alert me  

Replace Inline CSS Background:URL

by jmc15john :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having some difficulty replacing a background image used throughout a page I'm trying to modify.  The background:URL only shows up in a few tr's inside a couple different tables throughout the website.

Example of code from website:


------------------------------------------------------------------------------
<td style="height:25px; color:#FFFFFF; font-weight:bold; background:URL('./images/row_backgroud_grad.gif'); text-align:left;">Number</td>


 <table width="220" cellpadding="0" cellspacing="0" width="100%" id="header">
    <tr style="background:URL('./images/row_backgroud_grad.gif'); height:25px;">
--------------------------------------------------------------------------------


I would like to make a script to search through the website for row_backgroud_grad.gif and replace it with an image of my own.  

I've used this code to successfully replace images with with ID img and a src.

        var imgs = document.getElementsByTagName('img')
        imgs[0].src = "http://photo-hosting.winsoftmagic.com/1/99z7bc4lis.jpg"


And I've tried some stuff like this with XPath with no luck.  
         
------------------------------------------------------------------------------------
          var thisImg
          var backImg = document.evaluate("//img[contains(@src, 'row_backgroud_grad')",
                document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

            for (var i=0;i<backImg.snapshotLength;i++) {
              var thisImg = backImg.snapshotItem(i);
              var src = thisImg.src;
              var srcMatch = src.match('./images/row_backgroud_grad.gif');
              if (srcMatch != null) {
                thisImg.src = 'http://www.myurl.com/myimage/newback.gif';
              }
           }
-------------------------------------------------------------------------------------


Now I realize this above example won't work because it's trying to replace the string src which is not found in the inline style I am trying to edit.  I've tried replacing src with background:URL but I can't seem to get anything to work.  Any suggestions???

Thanks,

Jmc15john