Web Analytics Made Easy -
StatCounter show/hide script with error information - CodingForum

Announcement

Collapse
No announcement yet.

show/hide script with error information

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • show/hide script with error information

    i am trying to create a simple switch to turn the main navigation of a site "on" and "off". here is my script:

    Code:
    function nav_display() { // show/hide nav
    	if (document.getElementById('sidebar').style.display == 'none') {
    		document.getElementById('sidebar').style.display = 'block';
    		document.getElementById('content').style.margin-left = '1.5em';
    		document.getElementById('nav_display_a').style.color = '#666';
      } else {
    		document.getElementById('sidebar').style.display = 'none';
    		document.getElementById('content').style.margin-left = '170px';
    		document.getElementById('nav_display_a').style.color = '#FFF';
      }
    }
    
    <div id="nav_display_btn">
    <a id="nav_display_a" href="javascript:;" onclick="nav_display()" title="Click to show/hide the main menu.">&laquo;</a>
    </div>
    i am getting these errors:

    -from firefox-
    "Error: nav_display() is not defined"

    -from IE-
    "Error: Object expected"

    this is essentially a carbon copy of another function i was using in another spot on the site. which works fine. or should at least. it's not working for me now either. do i maybe have something wrong on my machine? this seems like elementary JS and DOM manipulation. i am confoozled.. in all fairness, it is 2:20 AM..

  • #2
    ah.. made the assumption that the margin property names were the same in JS when it in fact should be:

    Code:
    document.getElementByID('content').style.marginLeft
    it works now.

    Comment

    Working...
    X