Jump to content

Recommended Posts

Hi all, I was playing around with javascript a bit and thought that i could maybe make a button when pressed hide a div and when pressed again shows it again.

 

This is what i have so far, but it's not working, could anyone maybe point me in the right direction?

 

<script type="javascript">
                    function hideDiv(){
                    document.getElementById('divver').style.display = none;
                    }
            </script>

        <div id="divver">
            <input type="checkbox" id="scb1" name="scb1" value="1" />As Seen On Tv<br />
            <input type="checkbox" id="scb2" name="scb2" value="2" />Back To Basics<br />
            <input type="checkbox" id="scb3" name="scb3" value="3" />Bed Bath & Beyond<br />
        </div>
            
        <input type="button" onmouseover="hideDiv()" value="HIDE!!!"/>

 

I haven't added the show div part  because this first part isn't working yet.

I bet making a button switch from hide to show is done with an if statement and a numeric value which is set.

 

If anyone could see what i am doining wrong I would be very happy ::)

Link to comment
https://forums.phpfreaks.com/topic/214923-simple-hide-div-button/
Share on other sites

I changed the code a bit but still no succes.  :

 

 

<script type="javascript">                    function toggle(myobj) {    var el = document.getElementById(myobj);    if ( el.style.display != 'none' ) {        el.style.display = 'none';    }    else {        el.style.display = '';    }}            </script>        <div id="mydiv">            <input type="checkbox" id="scb1" name="scb1" value="1" />As Seen On Tv<br />            <input type="checkbox" id="scb2" name="scb2" value="2" />Back To Basics <br />            <input type="checkbox" id="scb3" name="scb3" value="3" />Bed Bath & Beyond<br />        </div>                    <input type="button" onmouseover="toggle(mydiv);" value="HIDE!!!"/>

 

OK i think i fixed it

I had to put single quotes around the value in the button like:

<input type="button" onmouseover="hideDiv('mydiv')" value="HIDE!!!"/>

 

Could someone maybe explain me why that is,  because within a function like below single quotes is not used? It's rather confusing for me at the moment.

function hide_me(divver){

//etc

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.