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.
ThanksI'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>
精彩评论