Results 1 to 6 of 6

Thread: Tab Content Script: trying to change colour for selected/not selected tab

  1. #1
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Tab Content Script: trying to change colour for selected/not selected tab

    DD Script: Tab Content Script
    url:http://www.dynamicdrive.com/dynamici...tabcontent.htm

    I am trying to change colour for selected/not selected tab, but I always get "tabobjlinks[..] is null or not an object" error.

    Code:
    function highlighttab(aobject){
    if (typeof tabobjlinks=="undefined")
    collecttablinks()
    for (i=0; i<tabobjlinks.length; i++)
    tabobjlinks[i].style.backgroundColor=initTabcolor
    tabobjlinks[i].style.color="white"
    var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor
    aobject.style.backgroundColor=document.getElementById("tabcontentcontainer").style.backgroundColor=themecolor
    aobject.style.color="#C35151"
    }
    I had changed the css too.
    Code:
    <style type="text/css">
    
    #tablist{
    padding: 3px 0;
    margin-left: 0;
    margin-bottom: 0;
    margin-top: 0.1em;
    font: bold 12px Verdana;
    }
    
    #tablist li{
    padding: 3px 0;
    list-style: none;
    display: inline;
    margin: 0;
    }
    
    #tablist li a{
    padding: 3px 3px;
    margin-left: 0px;
    margin-right: -3px;
    border: 1px solid #C5E1E9;
    border-bottom: none;
    background-color:#A5BCD3;
    color:#F3F8FD ;
    }
    
    #tablist li a:link, #tablist li a:visited{
    text-decoration: none;
    }
    
    #tablist li a.current{
    color:#C35151;
    background: #F3F8FD;
    text-decoration: none;
    }
    
    .tabcontent{
    display:none;
    }
    
    </style>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    When a statement follows a for statement, it will be executed for that situation. However, the following statement will not unless the situation described by the for statement is extended using brackets, examples:

    Code:
    for (whatever)
    dothis();
    dothat();
    In the above, dothis(); will be executed using the conditions set in play by the for statement but, dothat(); will not. If the code looks like so:

    Code:
    for (whatever) {
    dothis();
    dothat();
    }
    Now both dothis(); and dothat(); will execute in the environment laid out in the for statement. Taking this to your situation, you want:

    Code:
    for (i=0; i<tabobjlinks.length; i++) {
    tabobjlinks[i].style.backgroundColor=initTabcolor
    tabobjlinks[i].style.color="white"
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for your help.

    I am wondering, is it possible to state the css class for the tab that include background color, font color..etc instead of stating it one by one, had tried something like this

    Code:
    aobject.style = "current"
    but got error

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That would be:

    Code:
    aobject.className = "current"
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default So then...

    How do I keep a tab one color all the time regardless of where you click on the tabs?

    I would like let say the first initial tab always yellow.

  6. #6
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I had change the code to
    Code:
    function highlighttab(aobject){
    if (typeof tabobjlinks=="undefined")
    collecttablinks()
    for (i=0; i<tabobjlinks.length; i++)
    {
    	tabobjlinks[i].className = ""
    }
    var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor
    aobject.className = "current"
    }
    and is working now!

    I suppose if u want the tab to be same colour, u can try use the above code and set the css class "current" to be the same colour.

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
  •