1

So I am trying to make an expanding contact box but am having trouble with the javascript.. Current this is my code:

        function openTab() {

            var tab = document.getElementById('contact_body');

            if(tab.style.display = 'none') {
                tab.style.display = 'block';
            } else if(tab.style.display = 'block') {
                tab.style.display = 'none';
            }

        }

I am making it so that when you click the tab below it opens out (This part works) and then when you click it again, it closes (this does not work).

CLOSED:

enter image description here

OPEN:

enter image description here

The tab can be opened, but can't close, Why?

Thanks.

1 Answer 1

7

It should be two 'equals to' sign,

if(tab.style.display == 'none') 

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.