user770395
user770395

Reputation: 33

getElementbyID cannot access a style property to read or set it

I have some simple html/css where I am using an onclick event to send some parameters to a JavaScript. If one of them matches I then set the style.display property of the div to block so that it opens as a reaction to the link click. BUT I cannot get getElementById to work at all. Even a simple alert on the obj itself doesn't work. Below this is the line which is not working:

var displayprop = document.getElementById.("dashboardanchor").style.display;

Here is the code.

    Div nested several levels in other divs

    <div id="mainpagemenuboxcontainer">
        <div class="menulinkboxes" id="dashboarddiv">
        <a class="mainmenulinks" id="dashboardanchor"
        onmouseover='mouseOver("dashboarddiv")'
        onmouseout='mouseOut("dashboarddiv")'
        onclick='openPane("dashboarddiv,dashboardanchor")'
        href="#">Dashboard</a>
        </div>
    </div>

    <div id="mainpagecontainer">
        <div id="dashboardpane">dashboardpane</div>
        <div id="dcsmpane">dcsmpane</div>
        <div id="lgglasspane">lgglasspane</div>
        <div id="siprehashpane">siprehashpane</div>
    </div> <!-- End Mainpagecontainer -->

So what it does is turns on the div that you see right above. It's just a placeholder now but it should still go visible.

This is the Divs CSS.

    #dashboardpane {
    margin: 10px;
    padding: 5px;        
    font-family: monospace;
    background-color: white;
    border:1px solid blue;
    width: inherit;
    height: 700px;
    display: none;

}

This is the JavaScript function

    function openPane(elements)
     {
      var elements_array = elements.split(",");
      var paneDivId = elements_array[0];
      var paneAnchorId = elements_array[1];

      if (paneAnchorId == "dashboardanchor")
       {
        alert("gets to here");      
        var displayprop = document.getElementById.("dashboardanchor").style.display;
         // will not get to here
         alert (displayprop);
         document.getElementById.("dashboardanchor").style.display = "block";
       }
     }

Upvotes: 0

Views: 433

Answers (1)

Christopher Armstrong
Christopher Armstrong

Reputation: 7953

No dot - the ID is a parameter, not a method:

var displayprop = document.getElementById("dashboardanchor").style.display;

Upvotes: 1

Related Questions