SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Does not work in Firefox :/

    Hi,

    I'm trying to hide/show a <div> element. This works in Opera and IE but not firefox. Is there something wrong?

    Code:
    <script type="text/javascript"><!--
    function show(id,id2) {
    var element = document.getElementById(id);
    var element2 = document.getElementById(id2);
    var element3 = document.getElementById('linkPlugins');
    var element4 = document.getElementById('linkOthers');
    
    if (element == catPlugins) {
        element3 = document.getElementById('linkOthers');
        element4 = document.getElementById('linkPlugins');
    }
    
    element.style.display = 'block';
    element4.style.color = '#FFFFFF';
    element4.style.background = '#7FA6BC';
    element2.style.display = 'none';
    element3.style.color = '#000000';
    element3.style.background = '';
    }
    //--></script>
    And the links are:
    Code:
    <a class="stylename" id="linkOthers" href="" onclick="show('catOthers','catPlugins'); return false;">Others</a>
    
    <a class="stylename" id="linkPlugins" href="" onclick="show('catPlugins','catOthers'); return false;">Plugins</a>
    What happens in Firefox is that the page is reloaded.
    I tried change the call to javascript:show(); return false; in the href="" to no avail. No change happens.

    Any help is greatly appreciated.
    Thanks
    Last edited by lynlimz; Jun 14, 2004 at 08:14.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you have back slashes in your opening script tag? That's not standard syntax.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Opps, cause i was using php. I'll edit my post now.

    Any idea why it isn't working? Or is there a better method that might be more reliable in achieving the same effect?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is catPlugins, is it defined anywhere else? Have you looked at the JavaScript console, any error messages?

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Sorry. catPlugins or catOthers is the id of 2 separate div items.

    i.e.
    <div style="display: block" id="catPlugins">
    <div style="display: none" id="catOthers">

    which by default would show catPlugins and hide catOthers.

    The javascript console showed an error which say catPlugins is not defined. But it is. Any ideas?

    Thanks alot.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh goosh!
    I changed

    if (element == catPlugins) {
    to


    if (element == "catPlugins") {

    and it works now. but my style properties don't change in any of the browsers. Why?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, I managed to resolve the css property change problems by using className to define a different class instead.

    Thanks guys!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  8. #8
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    element is not a string, so (element == "catPlugins") is always false. Use if (id == "catPlugins") instead.

  9. #9
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh thanks, maybe that was why i couldn't get it to work, properly.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •