473,667 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show/Hide layer in Netscape/IE problem

Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape 7.1.

My function is in my head:

function openIt(faq) {
showIt = document.all(fa q);
if (showIt.style.d isplay == "none") {
showIt.style.di splay = ""
} else {
showIt.style.di splay = "none"
}
}

...and the onclick code is:

<a href="#" onclick="Javasc ript:openIt('22 list'); return false;">click
here to toggle</a>

<div id="22list" style="display: none">
This will show/hide when you click the above link
</div>
Could anyone help amend the function to run in both IE and Netscape?

Thanks for any help,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
5 6037
Mark wrote:
Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape 7.1.
I didn't even need to look at the rest of the code to see what was wrong.
I'm sure a search in google groups would have found the answer, it seems to
come up several times a week around here.

<http://www.metalusions .com/backstage/articles/8/> appears to be a
reasonable explanation.
<a href="#" onclick="Javasc ript:openIt('22 list'); return false;">click
here to toggle</a>
(1) The "Javascript :" in the onclickj event is redundent.
(2) href='#' is nasty. If you can't put a useful URL in there, don't use a
link
<div id="22list" style="display: none">


OK, I was wrong. I didn't guess what was wrong. Not everything at least. You
have two problems. The solution to the first is above, the other is that
ids may NOT begin with a number.

<http://validator.w3.or g/>

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #2
Mark hu kiteb:
Hi - I have a function which shows/hides a <div> on my page - this
appears to oinly work in IE, but I also need it to work in Netscape
7.1.

My function is in my head:

function openIt(faq) {
showIt = document.all(fa q);
if (showIt.style.d isplay == "none") {
showIt.style.di splay = ""


Change the above line to one of:

showIt.style.di splay = "inline";
showIt.style.di splay = "block";

And then be aware of the difference between them, and use them
appropriately.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #3
"Mark" <an*******@devd ex.com> wrote in message
news:3f******** *************@n ews.frii.net...
<snip>
function openIt(faq) {
showIt = document.all(fa q);
Netscape/Mozilla/Gecko browsers do not have a document.all collection so
the above line will produce errors and the rest of the function will not
be executed.

If the parameter - faq - contains a string that represents the unique ID
of an HTML element (as appears to be the case, with the caveat that
"22list" is not a valid ID attribute string according to the HTML 4
specification) then the W3C DOM standard document.getEle mentById method
could be used, possibly with a fall back to document.all to accommodate
IE 4.

Incidentally, document.all is an object so its named properties should
be accessed using square brackets instead of parenthesise. IE does its
error correcting/tolerance thing with code like this but other browsers
that do implement a document.all collection (there are quite a number
these days) may not be so tolerant.
if (showIt.style.d isplay == "none") {
showIt.style.di splay = ""
} else {
showIt.style.di splay = "none"
}
}

..and the onclick code is:

<a href="#" onclick="Javasc ript:openIt('22 list');
return false;">click here to toggle</a>

<div id="22list" style="display: none">

<snip>

Initially setting the display property to none means that any visitors
to the page who have JavaScript disabled/unavailable will be presented
with a non-functional/useful link and never be able to view the content
of the DIV (unless they view the page source). Generally, if content is
to be hidden and revealed with scripts it would be better to have it
initially visible and hide it in the onload event so that the content
will be available to the users without JavaScript. Additionally, the
link is meaningless without scripting so it should probably be included
in the document using a script, so that without client-side scripting
the user doesn't ever get the impression that there was any dynamic
mechanism on the page, and certainly not the impression that it is
broken.

Richard.
Jul 20 '05 #4
"Fabian" <la****@hotmail .com> writes:
Mark hu kiteb:

showIt.style.di splay = ""


Change the above line to one of:

showIt.style.di splay = "inline";
showIt.style.di splay = "block";


That's not necessary. Setting the properties of the element's style
object corresponds to writing in the tag's style attribute. Setting
a style object property to the empty string is consistently (across
current browsers) equivalent to removing the property from the
attribute value. It will then take its default value (or whatever
value is given by global CSS rules).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Hi - thank you for the replies - I'm not good with JavaScript though -
all I've been able to manage (after quite some time) is the code I've
shown - this was all through trial and error. Does anyone have a proper
routine which will both check for IE and Netscape, and toggle the
visibility/hidden/block (not sure which now!) between being shown and
not being shown - and not to leave a big gap if it is not shown?

Thanks again,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6

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

Similar topics

1
1299
by: Stephan | last post by:
I need a way to hide <div> that works in Mozilla/Netscape. My macromedia behavior does not work anymore. Also, and good ways to time the hideLayer? As in hide the layer after x seconds?? Thanks! Jeff
10
3201
by: David | last post by:
Hi everyone, Hoping there are some .js/browser experts out there that can help with this weird problem. I have made a swap div routine and applied the events to menu buttons with a closer layer behind the menus. The closer div has a lower index than the submenu divs so it appears behind them. The closer div contains a transparent gif with an event applied to it to close all of the divs when moused over.
5
2172
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the shown method is called, the table gets skewed and the presentation of the data on the page goes horribly wrong. I don't think this is a table issue as I have spent alot of time staring at this code. Here is the html...
3
14433
by: Ryh | last post by:
I have the following scritpt. It hides div layer when mouse is out of the div layer. Inside DIV I have IFRAME box. Unfortuantely it does not work in Mozilla or IE 5.5. It hides div when cursor is inside IFRAME. NOte that IFRAME is inside DIV so it should not hide DIV. It Works fine in IE6.0. Could any one help? Example:
3
6390
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath that layer further down uppon showing this layer. When a person closes that layer the content underneath the layer moves up again and closes the empty space. How is this possible? I am playing around with some code I am posting with this thread....
1
4165
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. I don`t want to change the way i have used to show and hide layers. check down code :- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
2
2140
by: dusk | last post by:
Hi, I have a page with lots of hidden divs which are revealed based on choices made at each 'layer'. So I've used naming convention which represents the order in which each div becomes visible - 'a100', 'a200', 'a300' for the first 'layer'; 'b100', 'b200', 'b300' for the second; 'c100, 'c200', 'c300' for the third ... etc I'm writing the javascript functions to hide and show the appropriate divs and its getting out of hand pretty...
1
3799
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown properties alt in img tag istead of picture . place of the pictures is saved in the database(my database is with mysql) and in home page i fetch properties of the product and address of place that pictures is located output of the code in the...
0
8457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8365
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8788
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.