Removing element by EQ filtering doesn't remove the element from jQuery Object

后端 未结 1 1718
温柔的废话
温柔的废话 2021-01-25 12:35

I used this code to match list of elements:

var previewItems = preview.find(\'.items\').children().not(\'.heads\');

Everything works fine, but

1条回答
  •  悲&欢浪女
    2021-01-25 12:42

    Why the jQuery keeps the element in the group of the matched elements?

    In case you want to do something with it after removing it. remove removes the element from the DOM, but you may well want to do something further (like adding it elsewhere in the DOM or retrieving information from it).

    You can remove it from the set using slice or not or filter (or more accurately: You can get a new object with all the same elements except the ones omitted by slice/not):

    previewItems.eq(index).remove();
    previewItems = previewItems.not(previewItems[index]);
    

    0 讨论(0)
提交回复
热议问题