开发者

Get attribute of objects in an array

For some reason, jQuery isn't giving me the attributes of objects in array when I define the number in the array. It will return the class of the first object in an array when none in particular are defined, though. For example, this works:

$开发者_如何学Go('#content').prepend($('div #left ol.group li',data).attr("class"));

but this doesn't:

$('#content').prepend($('div #left ol.group li',data)[3].attr("class"));

Can someone explain to me why this doesn't work like most other functions do and how to make it work?


with jQuery get the index by using eq

$('#content').prepend($('div #left ol.group li',data).eq(3).attr("class"));


Accessing an individual element of a jQuery set using the indexer returns a DOM object, which doesn't have the .attr() method. You want .eq(3), which returns a jQuery object wrapping that individual element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜