Javascript toggling multiple IDs

Show off new creations, get help, or just chat about all aspects of web development and design.

Javascript toggling multiple IDs

Postby dissonance on Sun May 25, 2008 10:19 pm

I'm trying to, with one link, both change a div's class (from filmContainer to filmContainerBig and back again) and toggle the visibility of another div (change infoContainer's visibility from none to block). I can get the class change working, but I can't seem to get the visibility toggle working. Any ideas?

the html:
Code: Select all
<html>
<head>
    <title>-test2-</title>
    <link rel="stylesheet" href="test2.css" type="text/css"/>
<script type="text/javascript">
function dostuff(x,y) {
   if (document.getElementById(x).className == 'filmContainer') {
      document.getElementById(x).className = 'filmContainerBig';
        document.getElementById(y).style.display = 'none';
   } else {
      document.getElementById(x).className = 'filmContainer';
        document.getElementById(y).style.display = 'none';
   }
}
</script>
</head>
<body>

<div class="filmContainerBig" id="testContainer">
    <div class="posterContainer">
        <img src="img/poster/test.1.jpg" class="poster" id="testPoster"/>
        <img src="img/static/overlay.png" class="overlay" onClick="dostuff('testContainer','infoContainer');"/>
        <div class="altPosterContainer">
            <a onClick="document.getElementById('test').src='img/poster/test.1.jpg'">1</a>
            <a onClick="document.getElementById('test').src='img/poster/test.2.jpg'">2</a></div>
    </div>
    <div class="infoContainer">
        <h2>Movie Title <em>(2008)</em></h2>
    </div>
</div>

</body>
</html>

and the css:
Code: Select all
div.filmContainer {
    width: 188px;
    height: 272px;
    margin: 2px;
    float: left;
}

div.filmContainer:hover {
    background-color: #b8cfe6;
    background-image: url('img/static/poster.hover.bg.png');
}

div.filmContainerBig {
    width: 572px;
    height: 272px;
    margin: 2px;
    float: left;
    background-color: #b8cfe6;
    background-image: url('img/static/poster.hover.big.bg.png');
}

div.posterContainer {
    display: block;
    float: left;
}

div.posterContainer .poster {
    width: 173px;
    height: 256px;
    background: url('img/static/poster.bg.png');
    padding: 8px 8px 8px 7px;
    position: absolute;
    z-index: 1;
}

div.postercontainer .overlay {
    width: 173px;
    height: 240px;
    position: relative;
    top: 8px;
    left: 7px;
    z-index: 2;
}

div.altPosterContainer {
    width: 173px;
    height: 16px;
    font-family: monospace;
    font-size: 13px;
    text-align: right;
    background-color: lightgreen;
    position: relative;
    top: 8px;
    left: 7px;
    z-index: 3;
}

div.altPosterContainer a {
    width: 15px;
    height: 16px;
    padding-left: 4px;
    padding-right: 4px;
    margin-left: -5px;
    margin-right: 0px;
    background-image: url('img/static/poster.link.png');
    color: #fff;
}

div.altPosterContainer a:hover {
    background-image: url('img/static/poster.link.hover.png');
    cursor: pointer;
    color: #000;
}

div.infoContainer {
    float: left;
    margin-left: 22px;
}
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Re: Javascript toggling multiple IDs

Postby zombie@computer on Mon May 26, 2008 8:39 pm

you are changing it to display: none in both cases :lol:
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Javascript toggling multiple IDs

Postby dissonance on Mon May 26, 2008 9:16 pm

zombie@computer wrote:you are changing it to display: none in both cases :lol:
=O
Oh lawd, how did I not see that?

[edit:] derp. Changed it and added `dispay: none;` to infoContainer's class, but it still ain't working. Do I need a && or somesuch thing in the javascript, either in the commands to be executed or in the if() question?
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Re: Javascript toggling multiple IDs

Postby zombie@computer on Tue May 27, 2008 4:40 pm

dissonance wrote:
zombie@computer wrote:you are changing it to display: none in both cases :lol:
=O
Oh lawd, how did I not see that?

[edit:] derp. Changed it and added `dispay: none;` to infoContainer's class, but it still ain't working. Do I need a && or somesuch thing in the javascript, either in the commands to be executed or in the if() question?

which will cause the class to contain a "dont render me"-part, and then you are still toggling that class from "dont render" to "dont render" and back? Offcourse that'll never work, or im not following ya
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Javascript toggling multiple IDs

Postby Jest@ on Mon Jun 16, 2008 7:09 pm

What zombie means is than in the if clause and the else clause you're setting it to display:none. The declaration in the stylesheet will give the initial setting, but you still need to set it to display:block in one of those places!

Edit: oh right, you said you'd changed that *and* set the stylesheet declaration. My bad. In that case, it should all be working, your syntax is fine etc. as far as I can see. If the class-change is working, the only think I can think of is the ID: Are you sure the ID for the 2nd element (y) is getting passed to the function properly? If you've got firefox, get the firebug add-on, go to the script panel and find your code, and set a breakpoint on the first line of the function. Then check the X and Y variable in the panel on the right in firebug.
Highlight to read:
It was earth all along
User avatar
Jest@
Veteran
Veteran
 
Joined: Mon Nov 22, 2004 1:50 am
Location: London UK

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users

cron