1
<script language="javascript"> 
        function switchdiv() {
       var e = document.getElementById().id;
       if(e == 'Streambtn')
          document.getElementById('Stream').style.display = "block";
       else
          document.getElementById('Stream').style.display = "none";
    }
</script>

Hello,

Here is my problem. When I click, nothing happen...

I hope you can help me.

Thank you

Edit :

Thank you for your answer zzlalani but it unfortunately does not work.

Here is the final code, hoping you'll help me to find a way to fix the problem.

   <div align="center">
    <input type="button" class="btn" name="Stream" value="Stream"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("Streambtn")"/>
    <input type="button" class="btn" name="Youtube" value="Youtube"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("Youtubebtn")"/>
    <input type="button" class="btn" name="LoL" value="League Of Legends"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("LoLbtn")"/>
    </div>
    <script language="javascript"> 
        function switchdiv(e) {
           if(e == 'Streambtn')
              document.getElementById('Stream').style.display = "block";
           else
              document.getElementById('Stream').style.display = "none";
        }
           if(e == 'Youtubebtn')
              document.getElementById('Youtube').style.display = "block";
           else
              document.getElementById('Youtube').style.display = "none";
        }
           if(e == 'LoLbtn')
              document.getElementById('LoL').style.display = "block";
           else
              document.getElementById('LoL').style.display = "none";
        }
    </script>
    <div align="center" id="Stream" hidden>
    <p>a</p>
    </div>
    <div align="center" id="Youtube" hidden>
    <p>b</p>
    </div>
    <div align="center" id="LoL" hidden>
    <p>c</p>
    </div>
4
  • how do you fire switchdiv() function? Commented Oct 10, 2013 at 19:47
  • 2
    var e = document.getElementById().id;, you need to pass an id to document.getElementById() in order to retrieve an element. That said, you're retrieving an id (with its id) in order to find its id? Commented Oct 10, 2013 at 19:48
  • Can you post the html code where u click on? do you call switchDiv()function? Commented Oct 10, 2013 at 19:49
  • how are you calling switchdiv? i mean show the code that is calling this function? Commented Oct 10, 2013 at 19:52

1 Answer 1

1

Let say you have button that calls switchdiv on click

<input type='button' onClick='switchdiv("Streambtn");' value='Stream!'>
<input type='button' onClick='switchdiv("nonStreambtn");' value='Non Stream!'>

Then it will goes like this

<script language="javascript"> 
    function switchdiv(e) {
       if(e == 'Streambtn')
          document.getElementById('Stream').style.display = "block";
       else
          document.getElementById('Stream').style.display = "none";
    }
</script>

The problem in you code is you are getting the value of nothing.. check it in this way

var e = document.getElementById().id;
console.log(e);

in the console of the browser you can see that will be either show some weird errors in red

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.