简体   繁体   English

我如何使用jQuery获取兄弟姐妹的孩子的ID

[英]How do I get the id's of children of siblings using jquery

I am using this code and it outputs the correct objects, but I am unable to get only the id from these objects. 我正在使用此代码,并且它输出正确的对象,但是我无法仅从这些对象中获取ID。 Here is the code: 这是代码:

console.log($(this).parent().parent().siblings().children());

Output is: 输出为:

[div#first-example.box-prop.top-widget, div#second-example.box-prop.top-widget, div#third-example.box-prop.top-widget, prevObject: init[3], context: i.fa.fa-times.close-x] [div#first-example.box-prop.top-widget,div#second-example.box-prop.top-widget,div#third-example.box-prop.top-widget,prevObject:init [3],上下文:i.fa.fa-times.close-x]

You can use .map : 您可以使用.map

var ids = $(this).parent().parent().siblings().children().map(function(e){
    return this.id;
}).get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM