Results 1 to 2 of 2

Thread: javascript: problem with splice method of array object

  1. #1

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    javascript: problem with splice method of array object

    Hello,

    I am having problems with the splice method of the array object

    Code:
    
    with getElementsByTagName, I am returning all img tags within a <div id="container">img, img, etc</div>
    
    
    imgs = container.getElementsByTagName("img");
    
    
    then i want to remove an element at some index
    
    
    imgs.splice(indexToRemove,1);
    
    
    I get an error saying that
    
    "Object doesn't support this property or method" 
    
    However if i do it to an array strings it works
    
    
    
    imgs = ["index1","index2","index3"];
    alert("the length of imgs is now" + imgs.length);
    imgs.splice(indexToRemove,1);
    alert("the length of imgs is now" + imgs.length);
    
    
    does this mean that splice cannot be used on an array of objects?

    thank you

    bsw

  2. #2

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292
    for those who care

    getElementsByTagName returns a collection not an array.

    that's why using splice wasn't working telling me

    "Object doesn't support this property or method"

    bsw

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