5 Replies Latest reply on Mar 25, 2008 12:55 PM by KeithGilbert

    [JS CS3] Trouble with getElements().length

      The "ScriptLabel.jsx" tutorial script has this code fragment:

      var myPageItems = myPage.pageItems.item("myScriptLabel");
      if(myPageItems.getElements().length != 0){
      alert("Found " + myPageItems.getElements().length + " page items with the label.");

      The script works fine as long as the page contains at least one pageItem with the label "myScriptLabel". However, if there are no labeled pageItems, the script fails because myPageItems.getElements().length is invalid.

      I can't figure out how to test for the condition of no pageItems having the label "myScriptLabel" to avoid this error. What am I missing?

      Thanks to anyone who can enlighten me!