Web Analytics Made Easy -
StatCounter img.length - CodingForum

Announcement

Collapse
No announcement yet.

img.length

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

  • img.length

    I belive the img.length would return me a number that is equel to the total amount of images.... right? (if i am wrong please correct me)

    However how can i tell it to give me the number of images that have the class name of "IMG"?

    thanks alot
    http://www.bluephoenix.uni.cc/

  • #2
    I don't know what img is, it has to be an array of some kind to be able to have the .length property.

    This link may give you some more insight:
    http://www.w3schools.com/dhtml/dhtml_dom_document.asp

    In particular, document.images will return a collection of all the images in the document. However, you want to be able to do a search of all elements that have className == "IMG"?

    I don't think there's a function that returns that. You'd have to write that yourself. If you have trouble with it, post back and perhaps someone can help you with it.

    Hope that helps,
    Sadiq.

    Comment


    • #3
      ele=document.images;
      eleCIMG=new Array();
      for(I=0;I<ele.length;I++)
      {
      if(ele[I].className=='IMG')
      {
      eleCIMG[eleCIMG.length]=ele[I];
      }
      }

      Comment


      • #4
        now it does I think
        Code:
        //Script:getElementsByClassName V1.0
        //Scripter:Garadon(Jens P. Svensson)[email protected]
        function getElementsByClassName(aClass)
        {
           function scanEle(aEle)
           {
             if(aEle==null)return;
             if(aEle.className==aClass){reselements[reselements.length=aEle}
             scanEle(aEle.firstChild);
             scanEle(aEle.nextSibling);
           }
           reselements=new Array();
           scanEle(document.firstChild);
           return reselements;
        }

        Comment


        • #5
          thanks a thousend times
          http://www.bluephoenix.uni.cc/

          Comment

          Working...
          X