473,383 Members | 1,953 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,383 software developers and data experts.

show/hide div problem

I'm using this code to show and hide a div.


Expand|Select|Wrap|Line Numbers
  1. function showDiv(){
  2. document.getElementById("test").style.visibility="visible"
  3. }
  4.  
  5. function hideDiv(){
  6. document.getElementById("test").style.visibility="hidden"
  7. }
  8.  
The link to hide the div is in another frame and it works fine.

When it is hidden a background image is visible and I've made it clickable with this:

Expand|Select|Wrap|Line Numbers
  1. #box-link { 
  2.         position: absolute; 
  3.         top: 21px; 
  4.         left: 21px; 
  5.         width: 267px; 
  6.         height: 180px; 
  7.         background-color: transparent; 
  8.         border: 1px solid yellow; }
  9.  
  10.  
and this:

Expand|Select|Wrap|Line Numbers
  1. <div class="box-link" id=test2><a id="box-link"  href="" onClick="javascript:showDiv()"></a></div>
  2.  
It works fine if I create a link in the other frame but it will not work in IE from the transparent box link div. Instead of making the div visible again, it goes to the directory page showing a list of files. It works perfectly in Firefox. But this is for an offline app in an app specific browser based on IE. So I don't care if it works in other browsers. Just IE.

Thanks in advance for any suggestions.
Sep 4 '10 #1

✓ answered by kovik

Okay... And your div would still appear and disappear, but every time that it did, the user would jump to the top of the page.

I'm still not sure what's so hard about adding the line "return false;" to the end of your functions, though...

10 2240
Well after spending a ridiculous amount of time trying to figure out the problem, I figured it out. All I had to do was add an # to the href=
Sep 4 '10 #2
kovik
1,044 Expert 1GB
You need for your event handler functions to return false.

That cancels the default action of the click, which is to navigate to the page in the href attribute. Setting the value to be "#" will only force the page to jump to the top.
Sep 5 '10 #3
Thanks for the reply. If what you mean by "jump to the top" is making the div visible, that is what I wanted. Regardless, it works now and all I did was add the #.

thanks
Sep 5 '10 #4
kovik
1,044 Expert 1GB
No, what I mean is that you are sending your users to the empty anchor (as opposed to an anchor like "#content" or "#nav"), which sends them to the top of the page. Once you have a page that is large enough to scroll, you'll see it.
Sep 5 '10 #5
The page is of a set size in an iframe. So that won't be an issue but for the sake of learning something, I changed it to #nav. The action is taking place in an iframe. There are two divs. One is a page and the other is a transparent image so that you can see a background image that is clickable. So the only page is the hidden div. But if everything was taking place on my main page and there was no iframe, in that case, without adding content or nav, my div would not reappear, but instead the main page would jump to the top?

Thanks again
Sep 5 '10 #6
kovik
1,044 Expert 1GB
Okay... And your div would still appear and disappear, but every time that it did, the user would jump to the top of the page.

I'm still not sure what's so hard about adding the line "return false;" to the end of your functions, though...
Sep 5 '10 #7
I'm only just learning. I didn't understand what you meant by return false before. I added it to the end of my functions. And now I know the proper way to do it.

Thank you.
Sep 5 '10 #8
kovik
1,044 Expert 1GB
Oh, okay. I didn't realize that was the issue. Good to see that we're on the same page, now. :)

Also, there's a difference between "visibility:hidden" and "display:none". The former makes the object invisible, but keeps it's position in the document so that no other elements are moved. The latter removes the element from the document (it can be restored by giving the display style a different value, such as "block").
Sep 5 '10 #9
In this case my hidden div has windows media player controls in it and it continues to play even when hidden. with display:none, would it close and stop playing?

thanks
Sep 5 '10 #10
kovik
1,044 Expert 1GB
No, it wouldn't. Though, you can probably force it to stop via JavaScript. How, I'm not sure. Sorry.
Sep 5 '10 #11

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

Similar topics

10
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
3
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and...
2
by: Mateo | last post by:
Hi! I have a litle JS problem.... I'm trying to make show/hide table JS function, but my show/hide table function works only on IE.... It works in mozilla partially. Actually,every time when I...
5
by: dje | last post by:
In the OnClick event on a radioButtonList, I run a javascript to show/hide the appropriate div along with a submit button, which displays as expected. The problem is the submit no longer works on...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
3
by: therealvibe | last post by:
I have made a simple page with show hide layers with javascript and css. http://www.icatt.nl/special/test/salarisstrook_algemeen.html The idea is that the blue help text rechtangle will have...
1
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
18
by: ryrocks | last post by:
Hi, Im making a 'contact us' page. The user click on the div, this then reveals another larger div displaying more information giving the effect of the box expanding or dropping down. I have 3...
17
by: may bailey | last post by:
Hi all, I have been trying to use a show / hide script on my web site but when I click on the "hide" button there occurs an error with explorer 7. The web site starts to go down =) and there...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.