how to check if div has id or not?

后端 未结 6 582
one
6条回答
  •  我在风中等你
    2021-01-12 13:14

    if(this.id) is all you need.


    Why will this work?

    If the element has an ID, the value will a non-empty string, which always evaluates to true.
    If it does not have an ID, the value is an empty string which evaluates to false.


    I am trying to get ids from the loop which are there.

    To get a list of IDs, you can use .map like so:

    var ids = $(".ui-droppable").map(function() {     
        return this.id ? this.id : null;
    }).get();
    

    or use the selector Roko suggests in his answer.

提交回复
热议问题