SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: class replace

  1. #1
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    class replace

    edit: nevermind, found solution.

  2. #2
    SitePoint Guru Rob_D's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It woudl be nice to see what your problem was and how you solved it.

  3. #3
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I needed to replace class of <tr> if inside that <tr> there is at least one <td> with certain class, and also replace certain images inside those <td>. So code that looks like this:
    Code:
    <tr>
      <td class="tcat"> ... </td>
      <td class="vbmenu_control"> ... </td>
      ...
    </tr>
    would be changed to
    Code:
    <tr class="tcat-row">
      <td class="tcat"> ... </td>
      <td class="vbmenu_control"> ... </td>
      ...
    </tr>
    After doing some research on similar problems this javascript did the trick:
    Code:
    	// find all <tr>
    	var rows = document.getElementsByTagName("tr"); 
    	var j = 0;
    	var row = false;
    	var item = false;
    	var change = false;
    	var imglist = false;
    	var attr = "";
    	for (var i = 0; i < rows.length; i++)
    	{ 
    	    row = rows[i];
    		change = false;
    		// check if there is <td class="tcat"> inside it
    		for(j = 0; j < row.childNodes.length; j++)
    		{
    			item = row.childNodes[j];
    			if(item.className == 'tcat')
    			{
    				change = true;
    			}
    		}
    		if(change)
    		{
    			// change row class
    			row.className = 'tcat-row';
    			for(j = 0; j < row.childNodes.length; j++)
    			{
    				item = row.childNodes[j];
    				if(item.className == 'vbmenu_control')
    				{
    					// change certain images location inside <td class="vbmenu_control">
    					imglist = item.getElementsByTagName("img");
    					if(imglist.length == 1)
    					{
    						attr = imglist.item(0).src;
    						if(attr.indexOf('menu_open.gif') > 0)
    						{
    							attr = attr.replace(/menu_open.gif/, 'menu_open2.gif');
    							imglist.item(0).src = attr;
    						}
    					}
    				}
    			}
    		}
    	}
    This saves me editing loads of template files for my first vbulletin template.

  4. #4
    SitePoint Guru Rob_D's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Good stuff


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
  •