开发者

attribute value

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

$开发者_JS百科('#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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜