Beginners question...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fix

    Beginners question...

    Hi,

    There probably is a very simple and basic solution for what i want, but i
    just don't know how...

    I have this script, which could be much shorter:

    function hidediv(id) {
    document.getEle mentById(id).st yle.display='no ne';
    }

    activated by:

    <div onclick="hidedi v('one');hidedi v('two');hidedi v('three')">cli ck</div>

    How can I adjust this script to activate it by:
    <div onclick="hidedi v('one','two',' three')">click</div>

    Thanks!


  • Martin Honnen

    #2
    Re: Beginners question...



    Fix wrote:[color=blue]
    > Hi,
    >
    > There probably is a very simple and basic solution for what i want, but i
    > just don't know how...
    >
    > I have this script, which could be much shorter:
    >
    > function hidediv(id) {
    > document.getEle mentById(id).st yle.display='no ne';
    > }
    >
    > activated by:
    >
    > <div onclick="hidedi v('one');hidedi v('two');hidedi v('three')">cli ck</div>
    >
    > How can I adjust this script to activate it by:
    > <div onclick="hidedi v('one','two',' three')">click</div>[/color]

    To have a function processing a variable number of arguments use the
    arguments array:

    function hideDivs () {
    var el;
    for (var i = 0; i < arguments.lengt h; i++) {
    if (document.all)
    el = document.all[arguments[i]];
    else if (document.getEl ementById)
    el = document.getEle mentById(argume nts[i]);
    if (el && el.style)
    el.style.displa y = 'none';
    }
    }



    --

    Martin Honnen


    Comment

    • Fix

      #3
      Re: Beginners question...


      Great! Thanks!!
      [color=blue]
      >
      >
      > Fix wrote:[color=green]
      > > Hi,
      > >
      > > There probably is a very simple and basic solution for what i want, but[/color][/color]
      i[color=blue][color=green]
      > > just don't know how...
      > >
      > > I have this script, which could be much shorter:
      > >
      > > function hidediv(id) {
      > > document.getEle mentById(id).st yle.display='no ne';
      > > }
      > >
      > > activated by:
      > >
      > > <div[/color][/color]
      onclick="hidedi v('one');hidedi v('two');hidedi v('three')">cli ck</div>[color=blue][color=green]
      > >
      > > How can I adjust this script to activate it by:
      > > <div onclick="hidedi v('one','two',' three')">click</div>[/color]
      >
      > To have a function processing a variable number of arguments use the
      > arguments array:
      >
      > function hideDivs () {
      > var el;
      > for (var i = 0; i < arguments.lengt h; i++) {
      > if (document.all)
      > el = document.all[arguments[i]];
      > else if (document.getEl ementById)
      > el = document.getEle mentById(argume nts[i]);
      > if (el && el.style)
      > el.style.displa y = 'none';
      > }
      > }
      >
      >
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]


      Comment

      Working...