Beginners question...

F

Fix

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.getElementById(id).style.display='none';
}

activated by:

<div onclick="hidediv('one');hidediv('two');hidediv('three')">click</div>

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

Thanks!
 
M

Martin Honnen

Fix said:
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.getElementById(id).style.display='none';
}

activated by:

<div onclick="hidediv('one');hidediv('two');hidediv('three')">click</div>

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

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

function hideDivs () {
var el;
for (var i = 0; i < arguments.length; i++) {
if (document.all)
el = document.all[arguments];
else if (document.getElementById)
el = document.getElementById(arguments);
if (el && el.style)
el.style.display = 'none';
}
}
 
F

Fix

Great! Thanks!!
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.getElementById(id).style.display='none';
}

activated by:

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

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

function hideDivs () {
var el;
for (var i = 0; i < arguments.length; i++) {
if (document.all)
el = document.all[arguments];
else if (document.getElementById)
el = document.getElementById(arguments);
if (el && el.style)
el.style.display = 'none';
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,573
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top