DevHunters.com l Webmaster Forum - Web Advertising - Web Design - SEO Forums  

Go Back   DevHunters.com l Webmaster Forum - Web Advertising - Web Design - SEO Forums > Webmaster / Coding / Web Design Discussion > JavaScript Programming

JavaScript Programming Discuss javascript coding.

Have A Look At Some Of Our Webmaster Related Sponsors!


Script Directory


Shopping Cart


Market Leverage


Free Templates

3D Guide-Characters
3D Guide-characters

social bookmarking network
Advertise Here

Reply
 
LinkBack Thread Tools Display Modes
Old 12-05-2007, 12:17 PM   #1 (permalink)
New Hunter
 

Join Date: Dec 2007
Posts: 1
iTrader: 0 / 0%
Hunter Bux: 0
xixao is on a distinguished road
Question Alternating dt/dd?

Hi everyone,

I've been searching everywhere for an answer, but have yet to find one. My problem is this:

I'm drawing news feeds dynamically on a client's site using iframes. The feeds come through as a definition list (dl), with the article titles as dt's, and their source as dd's. I've been able to alter the appearance of the list in a way that resembles a table, using the following:

PHP Code:
dl.i_rss {
    
width:95%;
    
margin:5px auto;
    
border:1px solid #ADBED6;
    
}
    
dl.i_rss dt {
        
padding:10px 5px 5px 5px;
        }
        
dl.i_rss dt a {
            
text-decoration:none;
            
font-size:12px;
            
font-weight:bold;
            }
    
dl.i_rss dd {
        
border-bottom:1px solid #ADBED6;
        
margin-left:0;
        
padding:5px 5px 10px 5px;
        }
        
dl.i_rss dd a {
            
text-decoration:none;
            
color:#999;
            
padding-right:15px;
            }
            
dl.i_rss dd a:hover color:#333; } 
A request has been made to have alternating rows in this "pseudo-table", so I need to somehow target every other dt and associated dd, and give it a different background color. There are no unique classes or other identifiers passed, so I'm unsure how to do this. The standard table row i%2 technique isn't working...

Here is how the list is coming through:

PHP Code:
<dl class="i_rss">
    <
dt class="rss_title">...</dt>
    <
dd class="rss_home">...</dd>
    <
dt class="rss_title">...</dt>
    <
dd class="rss_home">...</dd>
    <
dt class="rss_title">...</dt>
    <
dd class="rss_home">...</dd>
</
dl
Any suggestions?
xixao is offline   Reply With Quote
Old 01-14-2008, 12:37 PM   #2 (permalink)
New Hunter
 

Join Date: Jan 2008
Posts: 15
iTrader: 0 / 0%
Hunter Bux: 0
Toicantien is on a distinguished road
Default

You say you're loading this RSS feed in a client's site using an IFRAME? Is the client's page trying to access the IFRAME page using JavaScript, or is this RSS feed appearing wholly in the IFRAME and you just want a script that automatically parses the IFRAME for the RSS feed? If so, the following code should help out:
Code:
function alternateRows(el) {
  var i = 0;
  var end = 0;
  
  // Check for browser compatibility
  if (!document.getElementById || !document.getElementsByTagName) return;
  
  if (typeof(el) == "string") {
    el = document.getElementById(el);
  }
  
  switch (el.nodeName) {
    
    case "TABLE":
      for (i, end = el.rows.length; i < end; i++) {
        el.rows[i].className += i%2==0 ? "rowA" : "rowB";
      }
      break;
    
    case "DL":
      var dds = el.getElementsByTagName("dd");
      var dts = el.getElementsByTagName("dt");
      var className = "";
      
      for (i, end = dts.length; i < end; i++) {
        className = i%2==0 ? "rowA" : "rowB";
        dds[i].className += className;
        dts[i].className += className;
      }
      break;
    
  } 
}


window.onload = function() {
  if (document.getElementsByTagName) {
    var dls = document.getElementsByTagName("dl");
    var i = 0;
    var end = dls.length;
    
    for (i; i < end; i++) {
      if (dls[i].className.indexOf("i_rss") > -1) {
        alternateRows(dls[i]);
      }
    }
  }
};
You would place that code in the HEAD of the IFRAME HTML document. If this doesn't work, can you post more specifically how this RSS feed is being put on the client's page? This script will support both TABLEs and DLs.
Toicantien is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:56 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
vBCredits v1.4 Copyright ©2007, PixelFX Studios