Why my javascript is not working?

This is my Javascript:

<script type="text/javascript">
    function contactChange() {
        var contact = document.getElementbyId("contact");
        if (contact.style.display == "none") {          
            contact.style.display = "block";
        } else {
            contact.style.display = "none";
        }
    }
</script>

And here is my site:

http://www.andrewjalexander.com/

Why my javascript is not working?

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:

Why my javascript is not working?

It shows where the error happened (line 260 in your HTML/JS code) and what the error is(Object #<HTMLDocument> 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 <= 50 ) {
     console.log(scroll);
   we
    } else {
    $("#label").css('fill', 'none');
    $(".label").addClass(".transition");
 }
 if (scroll <= 150) {
    $(".sizeLG").css('color', '#ffffff');
 } else {
    $(".sizeLG").css('color', '#00000000');
    $(".sizeLG").addClass(".transition");
 }
});

});

answered Aug 29, 2018 at 8:30

Why my javascript is not working?

Make sure your id or class you used in html code will accordingly .(dot) Or #(hash) with their name.

Ex:

   For id:
   html:

  <div  id= idName>
          ****Some code****
   <\div>

  Javascript:
  var VariableName = document.querySelector( "#idName");
   Or
  var VariableName = document.getElementById( "#idName");

  For class:   
 html:
  <div  id= className>
          ****Some code****
   <\div>
  Javascript
  var VariableName = document.querySelector( ".className");
   Or
  var VariableName = document.getElementById( ".className");

answered Jun 23, 2021 at 17:44

What to do if JavaScript is not working?

On the web browser menu click on the "Edit" and select "Preferences". In the "Preferences" window select the "Security" tab. In the "Security" tab section "Web content" mark the "Enable JavaScript" checkbox. Click on the "Reload the current page" button of the web browser to refresh the page.

How do I run JavaScript in chrome?

Activate JavaScript in Google Chrome.
Open Chrome on your computer..
Click. Settings..
Click Security and Privacy..
Click Site settings..
Click JavaScript..
Select Sites can use Javascript..

How do I enable JavaScript to run this app?

Chrome Browser - Android - Turn JavaScript On / Off.
Apps icon. (Google) Chrome. . If unavailable, swipe up from the center of the display then tap. Chrome. ..
Tap the. Menu icon. (upper-right)..
Tap. Settings. ..
From the Advanced section, tap. Site settings. ..
Tap. JavaScript. ..
Tap the. JavaScript switch. to turn on or off ..

What is the problem with JavaScript?

These days, most cross-browser JavaScript problems are seen: When poor-quality browser-sniffing code, feature-detection code, and vendor prefix usage block browsers from running code they could otherwise use just fine. When developers make use of new/nascent JavaScript features, modern Web APIs, etc.)