Why is not working in javascript?

This is my Javascript:


    function contactChange[] {
        var contact = document.getElementbyId["contact"];
        if [contact.style.display == "none"] {          
            contact.style.display = "block";
        } else {
            contact.style.display = "none";
        }
    }

And here is my site:

//www.andrewjalexander.com/

asked Nov 28, 2011 at 1:48

4

It's document.getElementById, not document.getElementbyId. [In JS, name of variables and functions are case-sensitive]

Debugging tip : Look at the JS console [F12 in Google Chrome and IE9, Ctrl+Shift+K in Firefox]. In this case, following error can be seen:

It shows where the error happened [line 260 in your HTML/JS code] and what the error is[Object # has no method getElementbyId].

answered Nov 28, 2011 at 1:52

JiminPJiminP

2,09619 silver badges26 bronze badges

0

It's getElementById, not getElementbyId. Note the upper case "B".

hammar

137k17 gold badges298 silver badges383 bronze badges

answered Nov 28, 2011 at 1:52

CitoCito

5,05727 silver badges29 bronze badges

You're going to hate yourself for this, but you put getElementbyId[] instead of getElementById[]. Note the capitalized "B" in the second version.

answered Nov 28, 2011 at 1:53

chess007chess007

8266 silver badges7 bronze badges

Its getElementById in place of getElementbyId

answered Jun 27, 2017 at 16:24

Amaan IqbalAmaan Iqbal

7312 gold badges9 silver badges25 bronze badges

Try to hide then show a element on scroll I had to go this route. Basically i tried to use window so I used 'body'

$[document].ready[function[] {

$['body'].scroll[function[] {
 var scroll = $['body'].scrollTop[];
 if [scroll 

Chủ Đề