0

I have this code to showor hide a div when click on button.But... If you ckick button the div appear.. but when you click again the div doesnt dissapear:|
Code:

function infoshowhide(){

      if(document.getElementById('info11').style.display = 'none')
      {
        document.getElementById('info11').style.display = 'block';
      }
      else 
      {
        document.getElementById('info11').style.display = 'none';
      }

}

and i need something like this for final result :

function infoshowhide(){
     contentxinfo=document.getElementById('info') + 'x'; //x is a nr i wish to make an array... info1 ...or info2 .. info3...this thing

      if(document.getElementById(contentxinfo).style.display = 'none')
      {
        document.getElementById(contentxinfo).style.display = 'block';
      }
      else 
      {
        document.getElementById(contentxinfo).style.display = 'none';
      }
};

i wish to make an array... info1 ...or info2 .. info3...this thing
can you help me :D?

Edited by JamesCherrill: Moved to correct forum

4
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by bad.boy.Vlad
0

This fourum is for java too :D :p
Look on top of the page...

Software Development > Java > Showhide item

1

Here is a simple example you can use and modify it to fit you needs.

<!DOCTYPE html>
<html>
<head runat="server">
    <title>My Page</title>
<script type="text/javascript">

    function infoshowhide(id) {
        var e = document.getElementById(id);
        if (e.style.display == 'block')
            e.style.display = 'none';
        else
            e.style.display = 'block';
    }

</script>
</head>
<body>
<button onclick="infoshowhide('info11')">Show/Hide</button>
<div id="info11">Hello World!</div>
</body>
</html>

Edited by JorgeM

0

Thanks a lot for all replys

# You realy helped :D #

But i have one more question :))

function infoshowhide(id) {
    var e = document.getElementById(id);
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

i wish to make something like that:

 function infoshowhide(id) {
    var e = document.getElementById(id) + X; //x is not a var... just x... :D
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

how is corecct code for an array.. unite e with x :

Example:

e = info11
I need to change style for element with id info11x so i just need to add x to may variable..
How can i do this :D?

Edited by bad.boy.Vlad: not completed

1

hmm... so I may not be understanding you correctly, but you are asking that you just want to add the string value of "x" to the ID you are passing? Ok, if so, you have to do it before you assign the value of e. if you do this, then your element ID that you are targetting needs to be,in this case, "info11X" for this to still work.

function infoshowhide(id) {
    id = id + "X";
    var e = document.getElementById(id);
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

Edited by JorgeM

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.