Figuring out Hide/Unhide mode, in IE and Mozilla

M

mooeypoo

Hello all,

I'm a php developer. I have been using a very simple script to
hide/unhide divs in my script:

function DisplayI(obj)
{
obj.style.display=("none"==obj.style.display? "block" : "none");
}

the Div tag, looks like this:
<div id="blabla" style='display:hidden;'>

the ID of the Div is being compiled by a php script linked to a
Database (therefore, all DIVs get different ids).

It works perfectly in I.E, but in mozilla (firefox and netscape) it
doesn't.
If I change "display:hidden" to "display:block", it shows them open
completely (without hiding) throughout mozilla and I.E together.

I'm looking for a script that hide and unhides my divs and works in a
crossbrowser environment.
I've seen codes to solve the crossbrowser thing, but all of them
seperated "hidediv" and "showdiv" to two functions, and I need them
unified - the code to figure out if the div is shown and hide it, and
the other way around.

Can anyone please help me with this?


Thanks a lot!

~mooey
 
Z

ZER0

function DisplayI(obj)
{
obj.style.display=("none"==obj.style.display? "block" : "none"); ^^^^
}

the Div tag, looks like this:
<div id="blabla" style='display:hidden;'>

<div id="blabla" style='display:none'>

"hidden" is value of visibility style's attribute.
 
M

Mick White

mooeypoo said:
Hello all,

I'm a php developer. I have been using a very simple script to
hide/unhide divs in my script:

function DisplayI(obj)
{
obj.style.display=("none"==obj.style.display? "block" : "none");
}

the Div tag, looks like this:
<div id="blabla" style='display:hidden;'>



<div id="blabla" style='display:none;'> // note "display" property.
function DisplayI(id){
var obj;
if(obj=document.getElementById(id)){
obj.style.display=("none"==obj.style.display?"":"none");
return;
}
//if you arrive here, obj doesn't exist.
}

[snip]
Mick
 
M

mooeypoo

I have done all of that (changed display to none, and tried your code)
but now it doesnt' work in I.E aswell :( won't open my divs.

It doesn't even show an error, it just doesn't show my div in I.E or
Mozilla Firefox.

Ideas? :(

Thanks !

~mooey
 
A

ASM

mooeypoo a écrit :
I have done all of that (changed display to none, and tried your code)
but now it doesnt' work in I.E aswell :( won't open my divs.

It doesn't even show an error, it just doesn't show my div in I.E or
Mozilla Firefox.

Ideas? :(

re strat from beginning ...

<html>
<p><button onclick="mooey('poo');">yes no</button>
<div id="poo" style="display: none;height:150px;">
<h1>it is not a good idea</h1>
<p>Why ?
<p>Because without JS you'll can never see this div ...
</div>
<h2> Oh what a so terrific YoYo effect !</h2>

<script type="text/javascript">
function mooey(aDiv) {
var D = document.getElementById(aDiv).style;
D.display = D.display==''? 'none' : '';
}
</script>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top