www.webdeveloper.com
Results 1 to 4 of 4

Thread: Child Elements / Array

  1. #1
    Join Date
    May 2003
    Location
    UK
    Posts
    220

    Child Elements / Array

    Hello,

    How would I get all img elements' src values into an array from a parent div ID;

    Code:
    <div id="car_6c8859e4-4874-4ae1-b2b8-e2f76a7c10a0_photos" class="hidden">
    	<div class="gallery">
    		<div class="gal_thumbs">
    
    			<div class="gal_thumbs_cnt">
    				<a href="<imgpath>" onclick="displayPhoto('6c8859e4-4874-4ae1-b2b8-e2f76a7c10a0', '<imgpath>', '');return false;"><img src="<imgpath>" alt="<imgpath>" title="<imgpath>" /></a>
    			</div>
    
    		</div>
    	</div>
    </div>
    That's the base design. Being DB driven the number of images vary.

    Cheers

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,435

    Lightbulb

    Try this...
    Code:
    <script type="text/javascript">
    function imageIDS() {
      var str = '';
      var elems = document.getElementById("car_6c8859e4-4874-4ae1-b2b8-e2f76a7c10a0_photos").getElementsByTagName('img');
      for (var i=0; i<elems.length; i++) {
        str += elems[i].src+'\n';
      }
      alert(str);
    }
    </script>
    Code is untested as your example is incomplete

  3. #3
    Join Date
    May 2003
    Location
    UK
    Posts
    220
    Thanks. Your reply was enough to get me on my way. All sorted now.

    Thanks (Don't expect people to spoon feed me all the way for nothing!)

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,435
    You're most welcome.
    Happy to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles