Collapsible Menus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • develeigh@gmail.com

    #1

    Collapsible Menus

    Hi,

    I have got this Collapsible Menus, it uses combination of JavaScript
    and CSS.

    Javascript when executed changes the inital CSS settings to make the
    sub menu visable

    function toggleClamShell Menu(objectID) {
    var object = document.getEle mentById(object ID);
    if (object.style.d isplay == 'block')
    object.style.di splay='none';
    else
    object.style.di splay='block';
    return;
    }

    in CSS the initial settings hides the sub menus

    #menu1 { display: none; }
    #menu2 { display: none; }
    #menu3 { display: none; }

    In HTML using a tags to execute the javascript

    <a class="menuHead " href="javascrip t:toggleClamShe llMenu('menu1') ">

    It works perfectly in Firefox, IE, Safari but not in Opera to my
    suprise.

    Opera is not reporting any errors with the Javascript and I cannot see
    what it is that stops it working in Opera.

    If you know why it doesn't work in opera please let me know and any
    possible workarounds.

    Many Thanks in Advance

    Dafydd

  • Grant Wagner

    #2
    Re: Collapsible Menus

    <develeigh@gmai l.com> wrote in message
    news:1117453524 .674069.321890@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    > Hi,
    >
    > I have got this Collapsible Menus, it uses combination of JavaScript
    > and CSS.
    >
    > Javascript when executed changes the inital CSS settings to make the
    > sub menu visable
    >
    > function toggleClamShell Menu(objectID) {[/color]

    It's advisable to protect your call to document.getEle mentById():

    if (document.getEl ementById) {
    [color=blue]
    > var object = document.getEle mentById(object ID);[/color]

    It's advisable to test for the object and properties you want before
    assuming they are available:

    if (object && (object = object.style)) {
    [color=blue]
    > if (object.style.d isplay == 'block')
    > object.style.di splay='none';
    > else
    > object.style.di splay='block';[/color]

    If you are not applying the styles directly to the elements (ie - <div
    style="display: block;">) then you probably want to test against the
    default display style, rather than one specific to a specific element:

    object.display = (object.display == '' ? 'none' : '');
    [color=blue]
    > return;[/color]

    If you are not returning a value -return- is unnecessary.
    [color=blue]
    > }
    >
    > in CSS the initial settings hides the sub menus
    >
    > #menu1 { display: none; }
    > #menu2 { display: none; }
    > #menu3 { display: none; }
    >
    > In HTML using a tags to execute the javascript
    >
    > <a class="menuHead " href="javascrip t:toggleClamShe llMenu('menu1') ">[/color]

    It is in advisable to use href="javascrip t:...", see <url:
    http://jibbering.com/faq/#FAQ4_24 /> for an explanation.
    [color=blue]
    > It works perfectly in Firefox, IE, Safari but not in Opera to my
    > suprise.
    >
    > Opera is not reporting any errors with the Javascript and I cannot see
    > what it is that stops it working in Opera.
    >
    > If you know why it doesn't work in opera please let me know and any
    > possible workarounds.[/color]

    I'm guessing that the version of Opera you are using either does not
    support document.getEle mentById(), or does not support the style or
    display properties properly.

    It's also possible that moving the function call to an -onclick- event
    will resolve the problem.

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq


    Comment

    • Hallvord R. M. Steen

      #3
      Re: Collapsible Menus

      On Mon, 30 May 2005 13:45:24 +0200, <develeigh@gmai l.com> wrote:
      [color=blue]
      > I have got this Collapsible Menus, it uses combination of JavaScript
      > and CSS.[/color]
      <X>[color=blue]
      > It works perfectly in Firefox, IE, Safari but not in Opera to my
      > suprise.[/color]

      Perhaps you have a sample URL I can look at? The posted code was clear
      enough but it would still take me some time to write a test page, and I
      can not tell exactly what your menu markup looks like.
      --
      Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

      Comment

      Working...