Peavey2787
Peavey2787

Reputation: 138

Trouble with GetElementByID Not working

I've tried just about every possible combination of code, except obviously the correct one. All I'm trying to do is get the element by id in javascript/JQuery and display it in an alert. After reading some similar posts I've put the script after the body, I've put the code inside of document.ready, window.onload, and still nothing. Ultimately I have a button and a .button css class with a grey background image and .button:hover with a white background image. I would like to remove the .button class and replace it with a .buttonSelected class which has a dark grey background. TIA

    <div id="PlanningNav">
        <a href="~/Planning/Planning.cshtml">
            <div id="AboutMe" class="Button">
                <img src="~/Resources/Images/icoAbout_Me.jpg" height="20" width="@Button_Width" /> 
                &nbsp;&nbsp;&nbsp;   About Me
            </div>
        </a>
    </div>

<script>
window.onload = function () {
    var button = document.GetElementById('AboutMe');
    alert(button);
};
    $(document).ready(function () {
       var button;
       if (page.indexOf('About') > -1) { 
           button = document.GetElementById('AboutMe');
           alert(button.id); 
           // $('#AboutMe').removeClass('.Button');
           //$('#AboutMe').addClass('.ButtonSelected');
           // alert(button.innerHTML);
        } 
    });
</script>

Upvotes: 1

Views: 305

Answers (2)

CoOl
CoOl

Reputation: 2797

JavaScript is Case Sensitive, hence you need to make sure the casing.

your GetElementById would not work and as @dotnetom said, you need to change it to getElementById

Upvotes: 0

dotnetom
dotnetom

Reputation: 24901

JavaScript is case sensitive, so instead of

document.GetElementById('AboutMe');

You need to use

document.getElementById('AboutMe');

Upvotes: 3

Related Questions