Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript only "sees" one div tag

    I have two div tags in my HTML, all they do is encapsulate sections that I want to be able to hide/show via Javascript. Using the following script, only the first LAST div section can be identified. I've tried switching the order of the div tags, and still, only the last one is found. Can anyone guess what the problem might be, or show me a working example of how to do this with more than one div tag? BTW, the problem occurs on Mozilla 1.2.1 as well as IE 6.

    function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
    return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
    return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
    return document.layers[objectId];
    } else {
    return false;
    }
    }

    function changeObjectVisibility() {


    var angleField = getStyleObject("angleSection");
    var monthMenu = getStyleObject("monthSection");
    angleField.visiblity = 'hidden';
    monthMenu.visibility = 'hidden';
    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do both your DIV tags have the same id? Every element should have a unique id.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You have a typo


    angleField.visiblity = 'hidden'


    angleField.visibility = 'hidden'
    Last edited by Mr J; 12-18-2002 at 05:12 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •