简体   繁体   中英

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. 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]

You can use .map :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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