473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is there a way to make a DIV invisible using JavaScript

Hi:

I have sections on a page in asp panels. I would like to hide/show using
javascript, but don't see a visible property for DIV. How do you do this?

Thanks,
Charlie
May 5 '06 #1
6 6129
You can do it with css:

document.getElementById('theDivsId').style.display = 'none';

Set it to 'block' to make it visible again. This will work for any
element, not just divs.

Charlie@CBFC wrote:
Hi:

I have sections on a page in asp panels. I would like to hide/show using
javascript, but don't see a visible property for DIV. How do you do this?

Thanks,
Charlie


--
David Hogue
May 5 '06 #2
you can use

mydiv = document.getElementById("mydiv");
mydiv.style.display = "none"; //to hide it
mydiv.style.visibility = "block"; //to show it

HTH

Raj


"Charlie@CBFC" <fi********@verizon.net> wrote in message
news:OQ**************@TK2MSFTNGP04.phx.gbl...
Hi:

I have sections on a page in asp panels. I would like to hide/show using
javascript, but don't see a visible property for DIV. How do you do this?

Thanks,
Charlie


May 5 '06 #3
You are mixing display and visibility, that is not working.

Use either

mydiv.style.display = "none"; //to hide it
mydiv.style.display = "block"; //to show it

or

mydiv.style.visibility = "hidden"; //to hide it
mydiv.style.visibility = "visible"; //to show it
Rajesh CKR wrote:
you can use

mydiv = document.getElementById("mydiv");
mydiv.style.display = "none"; //to hide it
mydiv.style.visibility = "block"; //to show it

HTH

Raj
"Charlie@CBFC" <fi********@verizon.net> wrote in message
news:OQ**************@TK2MSFTNGP04.phx.gbl...
Hi:

I have sections on a page in asp panels. I would like to hide/show
using javascript, but don't see a visible property for DIV. How do
you do this?

Thanks,
Charlie

May 5 '06 #4
Hello fi********@verizon.net,

I like to separate things as much as possible by having all style related
stuf in CSS files. So, I would create a css class for each state and store
them in a css file:

..hiddenDiv {
display: none;
}
..visibleDiv{
display: block;
}
Then use JavaScript to switch the css class each time:

to hide:
mydiv.className = "hiddenDiv";

to show:
mydiv.className = "visibleDiv";

p.s. You can use "visibility" instead of "display", but there is a difference.
"visibility: hidden;" hides the DIV but it will still occupy the area it
took when it was visible. While "display: none;" will hide it and shift everything
around it to take up its space.
Hi:

I have sections on a page in asp panels. I would like to hide/show
using javascript, but don't see a visible property for DIV. How do
you do this?

Thanks,
Charlie


May 7 '06 #5
That's good info!

(PS, sorry i don;'t think the css itself is a good solution in this case)

"Jeeran" <je****@newsgroups.nospam> schreef in bericht
news:55*************************@msnews.microsoft. com...
Hello fi********@verizon.net,

I like to separate things as much as possible by having all style related
stuf in CSS files. So, I would create a css class for each state and store
them in a css file:

.hiddenDiv {
display: none;
}
.visibleDiv{
display: block;
}
Then use JavaScript to switch the css class each time:

to hide: mydiv.className = "hiddenDiv";

to show:
mydiv.className = "visibleDiv";

p.s. You can use "visibility" instead of "display", but there is a
difference. "visibility: hidden;" hides the DIV but it will still occupy
the area it took when it was visible. While "display: none;" will hide it
and shift everything around it to take up its space.
Hi:

I have sections on a page in asp panels. I would like to hide/show
using javascript, but don't see a visible property for DIV. How do
you do this?

Thanks,
Charlie


May 7 '06 #6
Hi,

Edwin Knoppert wrote:
That's good info!

(PS, sorry i don;'t think the css itself is a good solution in this case)


Why not?

If you really don't want to use CSS, you can also remove the node from
the DOM using JavaScript. Identify the node (with getElementById, for
example), and then remove it from its parentNode using removeChild.

Note however, that this will force a relayout of your document, which
might not be satisfactory. if you don't want a relayout, then you have
to use <element>.style.visible

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
May 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Mr. x | last post by:
Hello, Can I make my java script code be invisible to other people who enter into my site by IE browser ? - How ? Thanks :)
4
by: yabba | last post by:
is there a way to keep a client page invisible for a brief moment while it is checking a few things on the client with javascript? once checked it may need to redirect to another page... ...
2
by: john | last post by:
I have some controls that I want to be invisible, but if the user does something, they will become visible using javascript. So I can't set its "visible" property to false, because then they won't...
4
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images,...
3
by: rockdale | last post by:
Hi, All: I have a datagrid with TemplateColumn as following: <asp:TemplateColumn Visible="False" > <ItemStyle Width="0px"></ItemStyle> <ItemTemplate> <asp:Label id="lblMin_Value"...
21
by: abctech | last post by:
Hi all, I am working on a web application using JSP and Javascript. I have attached a snapshot of my form here, I have 2 different Jsps here, viz Jsp1 and Jsp2. On hitting the 'Show' button...
4
by: TS | last post by:
I am losing my colgroup html element of a table that i toggle back and forth of being visible=true/false. is there any workaround since the rendered html doesn't contain it even though it has not...
5
by: my.shabby.sheep | last post by:
Hi, I want to do the following. I want to make a table column invisible to the screen, but I still want to be able to get the innertext that would have been stored in the cell for certain...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.