Loading ...
Sorry, an error occurred while loading the content.

How can I make an arbitrary number of objects draggable?

Expand Messages
  • php08691
    Say I want to make all images on a page draggable. If I loop after using document.getElementsByTagName( img ) to get all the images, how can I draggability for
    Message 1 of 2 , Aug 30, 2007
    • 0 Attachment
      Say I want to make all images on a page draggable. If I loop after
      using document.getElementsByTagName("img") to get all the images, how
      can I draggability for each image? In other words, using the example
      var dd1 = new YAHOO.util.DD("element1"); how could I dynamically
      increment dd1 to dd2, dd3, etc. without knowing how many images are on
      a page?

      var allimages = document.getElementsByTagName("img");
      for(var i=0;i<allimages.length;i++)
      {
      var dd1 = new YAHOO.util.DD(allimages[i]);
      }
    • Chris Blessing
      I suppose you could store them in an array, like: var ddImgObjects = [] ; for(...) { ddImgs.push( new YAHOO.util.DD( allimages[i] ) ) ; } ...or write your own
      Message 2 of 2 , Aug 30, 2007
      • 0 Attachment
        I suppose you could store them in an array, like:

        var ddImgObjects = [] ;
        for(...)
        {
            ddImgs.push( new YAHOO.util.DD( allimages[i] ) ) ;
        }

        ...or write your own "DDImgCollection"  object to handle addition/deletion of new DD objects you wish to keep track of.

        This may not be the best performance-wise but at least you'll get a collection of objects to work with.

        -C

        php08691 wrote:

        Say I want to make all images on a page draggable. If I loop after
        using document.getElement sByTagName( "img") to get all the images, how
        can I draggability for each image? In other words, using the example
        var dd1 = new YAHOO.util.DD( "element1" ); how could I dynamically
        increment dd1 to dd2, dd3, etc. without knowing how many images are on
        a page?

        var allimages = document.getElement sByTagName( "img");
        for(var i=0;i<allimages. length;i+ +)
        {
        var dd1 = new YAHOO.util.DD( allimages[ i]);
        }

      Your message has been successfully submitted and would be delivered to recipients shortly.