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

display inherit and none switching in js with ie7

Hi all

This js i wrote to switch display on and off of a given element does
not work in ie but it does in ff and safari.

how can i make it work with ie guys?
<script type='text/javascript'>
function switch_display(switchme) {

curr_el = document.getElementById(switchme);
curr_dis = curr_el.style.display;

if (curr_dis != 'none') {
hidethis(curr_el);
}
if (curr_dis == 'none') {
showthis(curr_el);
}

return;

}

function hidethis(curr_el) {
curr_el.style.display = 'none';
}

function showthis(curr_el) {
curr_el.style.display = 'inherit';
}
</script>

<input type="button" onClick="switch_display('testdiv');" value="button
to switch display">

<div id="testdiv">some text
</div>

Jan 3 '07 #1
7 6744
>
This js i wrote to switch display on and off of a given element does
not work in ie but it does in ff and safari.

i should probably be more explicit, by 'does not work in ie' i mean it
will hide hidden text but will not display it again when u re-click the
button

Jan 3 '07 #2
libsfan01 said the following on 1/3/2007 11:22 AM:
>This js i wrote to switch display on and off of a given element does
not work in ie but it does in ff and safari.


i should probably be more explicit, by 'does not work in ie' i mean it
will hide hidden text but will not display it again when u re-click the
button
display:visible
display:hidden

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 3 '07 #3
Randy Webb wrote:
libsfan01 said the following on 1/3/2007 11:22 AM:
>>This js i wrote to switch display on and off of a given
element does not work in ie but it does in ff and safari.

i should probably be more explicit, by 'does not work in ie'
i mean it will hide hidden text but will not display it
again when u re-click the button

display:visible
display:hidden
The permissible values of the CSS display property (as defined in the
CSS 2.0 spec) are:- inline | block | list-item | run-in | compact |
marker | table | inline-table | table-row-group | table-header-group |
table-footer-group | table-row | table-column-group | table-column |
table-cell | table-caption | none | inherit

I am not sure why 'inherit' appears in that list as the property index
(appendix F) states that the property is not inherited.

Richard.
Jan 4 '07 #4
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>The permissible values of the CSS display property (as defined in the
CSS 2.0 spec) are:- inline | block | list-item | run-in | compact |
marker | table | inline-table | table-row-group | table-header-group |
table-footer-group | table-row | table-column-group | table-column |
table-cell | table-caption | none | inherit
Despite the fact that officially the 2.0 spec is the only CSS2.x spec
with Rec status, for practical web authoring CSS2.0 should be considered
obsolete and of historical relevance only. Authors should consult the
CSS2.1 Draft instead.
>I am not sure why 'inherit' appears in that list as the property index
(appendix F) states that the property is not inherited.
Not by default, but it can be if explicitly specified.
http://www.w3.org/TR/CSS21/cascade.h...ue-def-inherit

--
Spartanicus
Jan 4 '07 #5

libsfan01 wrote:
Hi all

This js i wrote to switch display on and off of a given element does
not work in ie but it does in ff and safari.

how can i make it work with ie guys?
<script type='text/javascript'>
function switch_display(switchme) {

curr_el = document.getElementById(switchme);
curr_dis = curr_el.style.display;

if (curr_dis != 'none') {
hidethis(curr_el);
}
if (curr_dis == 'none') {
showthis(curr_el);
}

return;

}
Display toggle functions are usually written something like:

function switch_display(switchme) {
var el = document.getElementById(switchme);
el.style.display = (el.style.display == 'none')? '' : 'none';
}

Don't forget feature detection.
--
Rob

Jan 4 '07 #6
Display toggle functions are usually written something like:
>
function switch_display(switchme) {
var el = document.getElementById(switchme);
el.style.display = (el.style.display == 'none')? '' : 'none';
}
Thanks Rob that works great. can anyone explain to me how this line of
code works:

el.style.display = (el.style.display == 'none')? '' : 'none';

what do the ? and : characters do, does it work something like, if
display equals 'none' then display becomes '' and if display = '' then
display becomes 'none'

are there any good online resources on this type of control structure?

thanks again :-)

marc

Jan 5 '07 #7
libsfan01 wrote:
>Display toggle functions are usually written something like:

function switch_display(switchme) {
var el = document.getElementById(switchme);
el.style.display = (el.style.display == 'none')? '' : 'none';
}

Thanks Rob that works great. can anyone explain to me how this line of
code works:

el.style.display = (el.style.display == 'none')? '' : 'none';

what do the ? and : characters do, does it work something like, if
display equals 'none' then display becomes '' and if display = '' then
display becomes 'none'
Yes, its the conditional operator:

<URL:
http://developer.mozilla.org/en/docs...ional_operator
>
and is a shortcut way of writing:

if (el.style.display == 'none') {
el.style.display = '';
} else {
el.style.display = 'none';
}

are there any good online resources on this type of control structure?
The FAQ lists a good selection of javascript resources (including the
Core JavaScript 1.5 Guide referenced above):

<URL: http://www.jibbering.com/faq/#FAQ3_2 >
--
Rob
Jan 5 '07 #8

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

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
1
by: Jon W | last post by:
This is a small table with hover on the table cells. The first cell is setup to switch from div element to input element by use of display:block/none. In IE, onclick the input element is displayed...
5
by: scott | last post by:
I'm trying to display a small "color square" to the left of each combo box choice. I know I can make each choice have a different background color, but is it possible to display a background image...
0
by: Jon W | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <html> <head> <title>rolly</title> <!-- The desired performance for this gem would be to: 1. click on table cells 2. edit in INPUT 3....
15
by: Markus Ernst | last post by:
Hi When toggling an element on and off by setting its display property via DOM access, display:none is valid for all kinds of elements, but I can't find anything about a generic value for...
4
by: DoomedLung | last post by:
I have been developing an image gallery which needed to be dynamic as possible. so I have placed the gallery in a div plus a div containing the large image to be displayed. It works by changing...
3
by: DoomedLung | last post by:
I have been developing an image gallery which needed to be dynamic as possible. so I have placed the gallery in a div plus a div containing the large image to be displayed. It works by changing...
7
by: khinester | last post by:
Hello, I have the following template that basically does the following: User select Country, then a sub-list is generated with Regions and then this returns the Counties ############### ...
19
by: Samuel Murray | last post by:
G'day everyone I'm trying to find out if there is a way (perhaps using CSS) to let this code: <table><tr><td>One Two Three</td></tr></table> display the same as if the code would have...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
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?

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.