开发者

Get attribute of objects in an array

开发者 https://www.devze.com 2023-02-20 00:29 出处:网络
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

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

精彩评论

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

关注公众号