views:

54

answers:

1

I have an atribute test that I get the value of like this

$('#row').attr("test");

now I need to put this in a loop and get the value but its not working. This is what I am doing

for(var i=0; i=mySpansCount; i++)  
{  
 var x=($('#row').attr("test"));  
 alert(x[i]);    
}

All I am getting in alert box is undefined.
Thanks

+1  A: 

I'm guessing that maybe you need to use .each() like this:

<div id="row">
    <span test="start">Hi </span>there, <span test="middle">I</span> am testing this <span test="end">out</span>.
    <div><span test="nested">Bye!</span></div>
</div>

<script type="text/javascript">
jQuery(function($) {
    $('span', '#row').each(function() {
        alert($(this).attr('test'));
    });
});
</script>
Lukman