View Full Version : returning all LI id's values from a UL

Mar 27th, 2007, 05:57 PM
I am trying to turn all the bullet points Li id values so i can store them.. I have written the code below but all this does it return the number of li's, everything i have done to bring out the id of the li, it fails.. can anyone help...

<script type="text/javascript">
function goRun(){
var list=document.getElementsByTagName('li');
for(i=0;i<list.length;i++) {
///////////////////////// page code...
<li id="v1">1</li>
<li id="v2">2</li>
<li id="v3">3</li>
<li id="v4">4</li>
<li id="v5">5</li>
<a href="javascript:goRun()">run</a>

i am trying to return a value that says v1,v2,v3,v4,v5 ?? any help

Bill Posters
Mar 27th, 2007, 06:44 PM
function goRun(){

var liEls=document.getElementsByTagName('li');
var liArray = new Array();

for(var i=0, liEl; liEl=liEls[i]; i++) {
liArray.push(liEl.id); // stores within an array object


Mar 27th, 2007, 09:22 PM
brilliant.. many thanks for that...