Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Toggling CSS "display"

  1. #1
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Question Toggling CSS "display"

    Hello,

    I'm using a piece of javascript, shown below, that was working fine before I put the site online. In fact, perhaps before I passed the site to my programmer buddy.

    Please take a look at this http://d599524362.bighost68.bighost.com.br/Namoda.aspx#

    The link below the image grid effects the css to hide the first grid and display another full of taste links. These links also use the toggle idea to hide the whole page and display divs containing photos. An alternative to pop-ups perhaps.

    Now it's online it's only working in IE. Damn!

    Any ideas? I'm looking for a quick fix so I can finish the site tonight/tomorning.

    Another problem with the same page:
    (let me know if I should be posting a new thread for this)

    I can't seem to limit the width of the div's containing the photos. "foto1", "foto2", etc. I'm included the css below. Any ideas please.



    #foto1,#foto2,#foto3,#foto4,#foto5,#foto6,#foto7,#foto8,#foto9,#foto10,#foto11,#foto12 {
    margin: 30px auto;
    position: relative;
    border: #695226 solid 1px;
    border-width: 1px 1px 2px 1px;
    padding: 0;
    }

    div#foto1 {
    width: 398;
    }

    #foto2 {
    width: 365;
    }



    Many thanks!

    Here's the javascript:



    function toggle(tag) {
    if (tag.style.display=='') {
    tag.style.display='none'
    } else {
    tag.style.display=''
    }
    }

    function togglegal(tag, tag2) {
    if (tag.style.display=='') {
    tag.style.display='none'
    } else {
    tag.style.display=''
    }
    if (tag2.style.display=='') {
    tag2.style.display='none'
    } else {
    tag2.style.display=''
    }
    }

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I think you should use document.getElementById

    Code:
    function toggle(tag) {
    var tag = document.getElementById(tag);
    if (tag.style.display=='') {
    tag.style.display='none';
    } else {
    tag.style.display='';
    }
    }
    
    function togglegal(tag, tag2) {
    var tag = document.getElementById(tag);
    var tag2 = document.getElementById(tag2);
    if (tag.style.display=='') {
    tag.style.display='none';
    } else {
    tag.style.display='';
    }
    if (tag2.style.display=='') {
    tag2.style.display='none';
    } else {
    tag2.style.display='';
    }
    }

  3. #3
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Unhappy

    thanks for trying but that's not changed anything.

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    May be you should make a backup page (sth like index_2.html) and place that script there and upload it to the script so that you could play with the script a little and you would still have the original page, in other hand we can also see what you've changed(and why it may not be working)

  5. #5
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Thumbs up

    Cool. I'll do that.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    shachi: You're wrong. document.getElementById() is not necessary in this case, it's perfectly correct to use element references as dog has done.

    dog: You haven't given us the whole code. That code contains three function definitions, but nowhere you've showed us are they actually called
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Talking

    Twey: thanks for the reply. I thought it'd be sufficient just to give a link to the site. You wanna see the html we're using to call the javascript, right?

    Here's an example from the menu. When you click on "Coleções" you should reveal "menuCollections". But this is only working in the damned IE.

    <img id="Uc_menu1_btnCollections" onclick="javascript:toggle(menuCollections)" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Uc_menu1_btnCollections','','images/menu-collections-ro.gif',1)" src="images/menu-collections.gif" style="border-width:0px;cursor:hand;" />

    <span id="menuCollections" style="display: none;">
    <input type="image" name="Uc_menu1$btnVizu" id="Uc_menu1_btnVizu" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Uc_menu1_btnVizu','','images/menu-vizu-ro.gif',1)" src="images/menu-vizu.gif" style="border-width:0px;" />

    Thanks for the help

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Aha -- here document.getElementById() is necessary You should be using:
    Code:
    onclick="toggle(document.getElementById('menuCollections'));"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    cheers!

    i'll try that right now!

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Oops sorry for the wrong advise Twey & dog.

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
  •