Expandable div help please RESOLVED

From C++ to PHP, debugging to webhosting; help and discussion about writing your latest program to running your website. NOT for help when your PC won't work.

Announcements Posted on
Sign in to Reply
  1. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Expandable div help please RESOLVED
    I have a problem with my html coding somewhere, and I can't figure it out. It works in IE and Chrome, but not in Firefox, and I need it to work in all browsers. Here's the link: http://kcldancesoc.co.uk/?page_id=711 You can see the source, if you're browsing in anything buy Firefox it should work.. I can't figure out why it won't in mozilla. Any ideas I'd really appreciate the help.
    Last edited by Zebrastripes; 20-11-2009 at 13:30.
  2. Dez's Avatar
    • TSR Group Staff
    • The square root of rope is string.
    • Location: The South
    • Posts: 8,221
    Re: Expandable div help please
    It's working fine for me, Firefox 3.5.5.
  3. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Re: Expandable div help please
    (Original post by Dez)
    It's working fine for me, Firefox 3.5.5.
    How strange! I'm using 3.5.5. too. I get 4's where the bullet marks are supposed to be, and it doesn't expand or do anything on clicking. That's why i put a disclaimer link in to go to a seperate page. Hmmm... don't know what's going on!!
  4. dave_chapman's Avatar
    • Full Member
    • Posts: 112
    Re: Expandable div help please
    Well the 4s are there because you've put them in the source code - they should be there in every browser, not just firefox. Use <ul> and <li> instead of Webdings as a lot of computers won't have it and I don't think firefox uses it.

    With regards to the javascript - firefox doesn't like window.event so I would use document.getElementById(id).styl e.display = 'block';

    You can do something similar to change the style of bullet points as well - look it up on w3c
  5. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Re: Expandable div help please
    (Original post by dave_chapman)
    Well the 4s are there because you've put them in the source code - they should be there in every browser, not just firefox. Use <ul> and <li> instead of Webdings as a lot of computers won't have it and I don't think firefox uses it.

    With regards to the javascript - firefox doesn't like window.event so I would use document.getElementById(id).styl e.display = 'block';

    You can do something similar to change the style of bullet points as well - look it up on w3c
    Thank you! Where do I but the document.getElementById(id).styl e.display = 'block'; ? Do i just replace the window.event with that?

    This is the script I'm using at the mo:

    <p><script>
    function exp(strTag ,strAttribute){
    var elem = document.getElementsByTagName(st rTag);
    var elem1 =window.event.srcElement;
    for (var i=0;i<elem1.children.length;i++) {
    elem1.children[i].innerText=="4"?elem1.children[i].innerText="5":elem1.children[i].innerText="4"; }
    for (var i =0;i<elem.length;i++)
    { if(elem[i].getAttribute(strAttribute)=="ye s")
    { elem[i].style.display=='none'? elem[i].style.display='block':elem[i].style.display='none';
    } } }
    </script> </p>
  6. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Re: Expandable div help please
    Okay so I'm now using this script which works, but it shows up expanded first, rather than collapsed.. how do i change this?

    <script type="text/javascript">
    function toggle(divName){
    if(document.getElementById)
    {
    var theDiv = document.getElementById(divName) ;
    if(theDiv)
    {
    if(theDiv.style.display == 'none')
    {
    theDiv.style.display = 'block';
    }
    else
    {
    theDiv.style.display = 'none';
    }
    }
    }
    }
    </script>
  7. darkraver's Avatar
    • Exalted and Worshipped Member
    • Location: UK
    • Posts: 1,077
    Re: Expandable div help please
    (Original post by Zebrastripes)
    Okay so I'm now using this script which works, but it shows up expanded first, rather than collapsed.. how do i change this?
    You will need to use CSS to change every 'expandable' div's 'display' attribute to 'none'

    Ie:

    Let's say you have a div which is expandable called 'howdy'

    Then you may have:

    <div id="howdy">...</div>

    Replace that with

    <div id="howdy" style="display: none">...</div>

    Actually that won't work very well, it will remove the 'title' text as well.

    Can I suggest a better alternative that is guaranteed to work on every browser?
    Last edited by darkraver; 14-11-2009 at 12:50.
  8. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Re: Expandable div help please
    (Original post by darkraver)
    You will need to use CSS to change every 'expandable' div's 'display' attribute to 'none'

    Ie:

    Let's say you have a div which is expandable called 'howdy'

    Then you may have:

    <div id="howdy">...</div>

    Replace that with

    <div id="howdy" style="display: none">...</div>

    Actually that won't work very well, it will remove the 'title' text as well.

    Can I suggest a better alternative that is guaranteed to work on every browser?
    Yes please!
  9. Zebrastripes's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: UK
    • Posts: 4,448
    Re: Expandable div help please
    Actually, adding style="display none" works! I'm not really using div.. so its like <ul id="choreo" style="display: none"> Thank you!!!
  10. darkraver's Avatar
    • Exalted and Worshipped Member
    • Location: UK
    • Posts: 1,077
    Re: Expandable div help please
    Well if it works, then that's great. I thought the title/heading text was contained inside the div as well, so it would remove that too. But if it works, then great!

    I was going to suggest jQuery which gets rid of all your browser related problems and simplifies DOM handling + JS scripting.
  11. Baron's Avatar
    • Vengeful, Imperial Overlord of The Student Room
    • Location: London
    • Posts: 4,863
    Re: Expandable div help please
    If you want to support non javascript browsers, it might be good to have the CSS set the accordion expanded by default and then close it with javascript on body load.
Sign in to Reply
Share this discussion:  
Useful resources
Article updates
Moderators

We have a brilliant team of more than 60 volunteers looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Reputation gems:
The Reputation gems seen here indicate how well reputed the user is, red gem indicate negative reputation and green indicates a good rep.
Post rating score:
These scores show if a post has been positively or negatively rated by our members.