jquery - Javascript: Array loop and outputting text -


how put div id tag array output image's alt text using loop?

for e.g., have following code...

<div id="imagegallery" style="left: 800px; position: absolute; top: 200px">  	<center>  		<table border="0" cellspacing="0" cellpadding="3">  		<tr>  			<td><a href="#"><img alt="random image 1" src="../images/thumbnails/random1.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  			<td><a href="#"><img alt="random image 2" src="../images/thumbnails/random2.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  			<td><a href="#"><img alt="random image 3" src="../images/thumbnails/buckstb01.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  		</tr>  		</table>  		<table border="0" cellspacing="0" cellpadding="3">  		<tr>  			<td><center><a href="#"><img alt="random image 4" src="../images/thumbnails/portrait.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></center></td>  		</tr>  		</table>  	</center>  </div>

i put id "imagegallery" array , output it's alt text afterwards.


to caius

i've tried many different variations.

var imagegallery = [ $( "#imagegallery img" ) ];  for( = 0; <= imagegallery.length; i++ ) {      $( "#imagegallery" ).attr( "alt" ); } 

sometimes print out 1 letter @ time or 1 set @ time, when want whole set.

i can't remember if did way tried many different variations , forgot save didn't work.

// here array  var images = document.queryselectorall('#imagegallery img');    for(var = 0; < images.length; i++){    // output alt's in loop    console.log(images[i].getattribute('alt'));  }
<div id="imagegallery" style="left: 800px; position: absolute; top: 200px">  	<center>  		<table border="0" cellspacing="0" cellpadding="3">  		<tr>  			<td><a href="#"><img alt="random image 1" src="../images/thumbnails/random1.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  			<td><a href="#"><img alt="random image 2" src="../images/thumbnails/random2.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  			<td><a href="#"><img alt="random image 3" src="../images/thumbnails/buckstb01.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></td>  		</tr>  		</table>  		<table border="0" cellspacing="0" cellpadding="3">  		<tr>  			<td><center><a href="#"><img alt="random image 4" src="../images/thumbnails/portrait.jpg"  			style="border-color: #000000; border-width: 2px; border-style: ridge"></a></center></td>  		</tr>  		</table>  	</center>  </div>


Comments