473,402 Members | 2,053 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,402 software developers and data experts.

hiding divs

111 100+
I have a very simple javascript question.

here is some code,
which i can't seem to get working
<html>
<body>
<script type="text/javascript">
function change_status(item) {
var status = document.getElementById(item).style.display;

if (status=='none')
document.getElementById(item).style.display = 'block';
else if (status =='block')
document.getElementById(item).style.display = 'none';
}
</script>

<div style="cursor:pointer" onclick="change_status('images_left_holder')">Imag es</div>
<div id="images_left_holder">
<div>asdf adsf adsfsdds sds ssd sf f ads </div>
</div>

</body>
</html>


When someone clicks on the text 'image' i want the div with the random text to hide/appear.

I've done this dozens of times, but this time it just doesn't seem to work.
i tried the above code in both IE and mozilla. there are no errors being thrown by either browser
Aug 6 '07 #1
4 1214
Logician
210 100+
When someone clicks on the text 'image' i want the div with the random text to hide/appear.

I've done this dozens of times, but this time it just doesn't seem to work.
i tried the above code in both IE and mozilla. there are no errors being thrown by either browser
What if the default value of .display hasn't been set explicitly, and therefore is ""?
Aug 6 '07 #2
nitinpatel1117
111 100+
i tried setting the default value to 'none' and still it never worked.


<style>
#images_left_holder{
display:none;
}
</style>


the above style, did hide the div but the div did not re-appear after i clicked on the 'image' text.
Aug 6 '07 #3
Logician
210 100+
i tried setting the default value to 'none' and still it never worked.


<style>
#images_left_holder{
display:none;
}
</style>


the above style, did hide the div but the div did not re-appear after i clicked on the 'image' text.
The style must be declared inline, or it isn't readable.
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <script type="text/javascript">
  3. function change_status(item)
  4. {
  5.  var status = document.getElementById(item).style.display;
  6.  document.getElementById(item).style.display = (status=='none'?'block':'none');
  7. }
  8. </script>
  9.  
  10. <div style="cursor:pointer" onclick="change_status('images_left_holder')">Images</div>
  11. <div id="images_left_holder" style="display:block">
  12.  <div>asdf adsf adsfsdds sds ssd sf f ads </div>
  13. </div>
  14. </body>
  15.  
Aug 6 '07 #4
nitinpatel1117
111 100+
thanks logician,

It does work now,
and it also explians why it worked earlier for me, becuase i'm tring to remove all inline styles into external style sheets, but i guess i will have to leave this one

thanks again.
Aug 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris Hughes | last post by:
I have a routine that creates a page with 2 sets of tables with divs around them. Each div tag has a name. The first set of tags are as follows div id="T123" STYLE="display: none;"> div...
8
by: Rob McLennan - ZETLAND | last post by:
Hi, I have set up an external stylesheet, named "print.css", to format the style of all pages printed from my company's website. I've been previewing my changes to the stylesheet by doing...
5
by: mt | last post by:
In a nutshell, I'd like to have a list of items, each of which fills out a small table which displays some info about a particular item(the items being a trouble ticket for a tech support ASP-built...
9
by: middletree | last post by:
I'm doing an ASP-built Intranet app, and am having trouble with a bit of code on the menu I am using. I got it from some free site, but I tried emailing the person whose email address is in the...
39
by: WindAndWaves | last post by:
Hi Gurus I have a page, which looks a bit like this: .... <body> <div ID=id1>................</DIV> <div ID=gsd>................</DIV> <div ID=ewd>................</DIV> <div...
5
by: gregmercer | last post by:
I have the following html sample, where I'd like to have a show and hide two divs, one replacing the other. Following these two divs is a third div (the bluediv) which I would like to have placed...
24
by: Kourosh | last post by:
I have a lot of DIV tags on an HTML page. I want to group some of them so that I can hide them all together at once if needed. What's a good way to do this? I want this to be compatible with at...
1
by: jarrodprice | last post by:
If I had 4 divs, box1, box2, box3 and box4, and I wanted a script to make certain combinations of them visable controlled by a number sequence in a second div called: "1to4". The script should be...
1
by: roland-d | last post by:
Hello all, Toggling divs is a popular subject and I have found plenty of information and was able to make it work. There is only 1 thing I am still stuck with for quite some time. I have a...
7
by: zenbob | last post by:
Greetings, and thanks in advance for considering my problem. I am working in a basic .htm page, in which I want to close all displayed DIVs with one event. In IE, I find that this works: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.