CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    May 2006
    Posts
    306

    [RESOLVED] Try catch for checking element

    Okay, so here's the deal. I have a function that runs through a for loop, and picks elements and adds them to an array. I don't want to add an element that's not there, so I want to set up a try catch so that it can catch an error and hopefully return when it's trying to get an id that's not there.

    How do I check if the generated element id is valid?
    Or is there someway I can get the last child in a node, regardless of id?

    Code:
    <div id="mainDiv">
        <div id="subDiv1"></div>
        <div id="subDiv2"></div>
        <div id="subDiv3"></div>
        <div id="subDiv4"></div>
        <div id="subDiv5"></div>
    </div>
    Here is some sample code.

    HTML Code:
    function getElements()
    {
        var elemArray = new array();
        for (var i = 1; i < 9; i++)
        {
            var elem = document.getElementById("subDiv" + i);
            elemArray[i - 1] = elem;
        }
    }
    Last edited by code?; August 9th, 2008 at 02:40 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured