Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

hiding a DIV in another frame . . .

Javascript coding ..

Moderators: macek, egami, gesf

hiding a DIV in another frame . . .

Postby WoozyDuck » Mon Sep 13, 2004 8:51 pm

Hi

how can I hide a DIV in another frame by JavaScript ?
User avatar
WoozyDuck
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed May 05, 2004 10:14 am

Postby gesf » Tue Sep 14, 2004 8:39 pm

Example:
Code: Select all
<div name="mdiv">whatever</div>

If you want it always hidden you can make a style for it:
Code: Select all
.invisible {
   display: none;
}

// And then...

<div name="mdiv" class="invisible">whatever</div>
Or just using:
Code: Select all
<div style="display: none;">whatever</div>

If you want to hide and show it, with javascript, you can do:
Code: Select all
<script type="text/javascript" language="javascript">

function HideShow() {
   mydiv = document.getElementById('mdiv').style.display;
   if(mydiv == 'none'){
       mydiv = '';
   }
   else{
       mydiv = 'none';
   }
}

// So, calling this function will hide and show it depending on its status
// Not sure, but i think it will work :p

</script>
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby WoozyDuck » Wed Sep 15, 2004 11:47 am

Well the correct cide is :

Code: Select all
<script type="text/javascript" language="javascript">
function HideShow() {
    if (document.getElementById('mdiv').style.display == 'none')
    {
      document.getElementById('mdiv').style.display = '';
    } else
    {
      document.getElementById('mdiv').style.display = 'none';
    }
}   
</script>



and we have to set ID (not name) in DIV if we wanna use getElementById , like this :

Code: Select all
<div id="mdiv">whatever</div>



by the way Ive found my answer ,
we can call our function from other frame like this (main is the name of our frame):

Code: Select all
parent.main.HideShow()


thanx a lot for giving me the tip , because your idea gave me
how to make this code works :) it was helpful and I appreciate that

Cheers
User avatar
WoozyDuck
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed May 05, 2004 10:14 am

Postby gesf » Thu Sep 16, 2004 1:41 am

That was just an example. I actually use the tag's name and id at the same time regarding old browsers and/or its incompatibility.
Code: Select all
parent.main.HideShow()
Yep, you can also call it e.g.: on the body's onload or something!

Cheers
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby WoozyDuck » Thu Sep 16, 2004 6:39 am

Thanx a lot mate :)
User avatar
WoozyDuck
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed May 05, 2004 10:14 am


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron