changing specific <div> status

R

richard

I have <div id=box1 style="display:block"> as the initial setting.
I need to change the "display:block" to "display:none" then back to
"display:block" as a means of clearing anything that might be
displayed within the box1 division.

What's the simplest way of doing this?
 
R

rf

richard said:
I have <div id=box1 style="display:block"> as the initial setting.
I need to change the "display:block" to "display:none" then back to
"display:block" as a means of clearing anything that might be
displayed within the box1 division.

Changing the display property as above will *not* achieve "clearing anything
that might be displayed".
 
R

richard

Changing the display property as above will *not* achieve "clearing anything
that might be displayed".

As I have found out this is true.
So what will?
 
R

rf

richard said:
As I have found out this is true.
So what will?

document.getElementById("box1").innerHTML = "";

but why? If you don't want stuff displayed in the div then don't put it in
there.
 
D

Doug Gunnoe

As I have found out this is true.
So what will?

What do you mean by "clearing anything that might be displayed"?

In other words, you are not merely interested in toggling the
visibility of the div, but you want to empty the contents of the div
also?

If that is what you're getting out, maybe consider altering the
innerHML attribute of the div.

someDiv.innerHTML = "";
 
R

richard

document.getElementById("box1").innerHTML = "";

but why? If you don't want stuff displayed in the div then don't put it in
there.

Now that, is the response I would expect from a 10 year old.

I am attempting to design a menu system that will that will have 3
levels of choices.
Yeah sure I could use those premade scripts that show your choices as
long as the cursor is over that item. But I need stability.

Item 1 has only one choice.
Items 2 and 3 will have two sublevels to choose from.
Item 4 will have one level.
All of which is contained within "box1".
What you see displayed is the content of your first level item choice.
So why show the others?


Of course, I could just as well write a seperate page for each choice
but that would mean keeping track of that many more pages.
 
R

richard

What do you mean by "clearing anything that might be displayed"?

In other words, you are not merely interested in toggling the
visibility of the div, but you want to empty the contents of the div
also?

If that is what you're getting out, maybe consider altering the
innerHML attribute of the div.

someDiv.innerHTML = "";


Only as far as displaying the content goes, not the complete removal
of the division.
 
R

rf

richard said:
Now that, is the response I would expect from a 10 year old.

Well while we are here I might point out that your question, with no
explanation at all for the questions reason, and presuming a "solution" that
is so totally wrong that we all learnt it in HTML 101 stuff, is what I would
expect from a 10 year old.

Do you want help with this or not? If not then you are going about it
exactly the right way.
I am attempting to design a menu system that will that will have 3
levels of choices.

Bad idea. These things are not accessible, unless you take great pains to
make them so. How will I get to those lower level items if I don't have a
mouse? You are, of course, making provision for that, aren't you?
Yeah sure I could use those premade scripts that show your choices as
long as the cursor is over that item. But I need stability.

So use one of them and modify it to suit your needs? From your original "10
year old" question it might just be better though if you don't attempt to
modify it.
Item 1 has only one choice.
Items 2 and 3 will have two sublevels to choose from.
Item 4 will have one level.
All of which is contained within "box1".

Why. Why not give them each a different box. You are going about this
entirely the wrong way, but then again this is your usual modus operandi.

And how did you get the menu items in the div in the first place?
What you see displayed is the content of your first level item choice.
So why show the others?

Why fart about with changing the contents of one single div? Why not do it
like all the other dropdown menu scripts (and CSS alternatives) out there?
Use one div per dropdown. Then all you have to do is swich the display mode
to 'block' for the active one.
Of course, I could just as well write a seperate page for each choice
but that would mean keeping track of that many more pages.

What? Who said anything about pages? We are talking about divs here. If you
can't keep track of four (yes, I counted) divs then maybe writing web pages
is not what you should be doing. Driving trucks, perhaps?
 
G

Gregor Kofler

richard meinte:
Only as far as displaying the content goes, not the complete removal
of the division.

See the solution above or - perhaps more standards compliant - something
like:

someDiv.childNodes.length = 0;

or

while(someDiv.hasChildNodes()) {
someDiv.removeChild(someDiv.lastChild);
}

Anyway, you've been told before that this whole approach for your
drop-down menu is idiotic.

"Yeah sure I could use those premade scripts that show your choices as
long as the cursor is over that item. But I need stability."

LOL. So you are replacing the not-too-stable premade scripts, by your
own solution, without having the slightest clue of JS and DOM scripting.
Interesting.

(Does this make me a "ten-year-old"?)

Gregor
 

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

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,794
Members
47,342
Latest member
eixataze

Latest Threads

Top