开发者

jquery map() function returns undefined

开发者 https://www.devze.com 2023-02-05 09:59 出处:网络
i got a problem with the map function, maybe i got it wrong. i have a menu that consists of div layers (here is one item)

i got a problem with the map function, maybe i got it wrong. i have a menu that consists of div layers (here is one item)

<div class='menu_item inner_node' hash='4' depth='0'>Portfolio</div>

if some one click it the css class selected is added to that item. now i want to get all selected menu items with map() like this:

$("div.selected").map(function()
{
    return $(this).attr("hash");
}
).get().join(", ");

i just need the "hash" attribute from it. i made an example here: Example the output is undefined everytime... what is wr开发者_运维技巧ong with the script?

regards, peter


You're missing a return in function get_hash().

http://jsfiddle.net/gruhH/1/

0

精彩评论

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