jQuery使从DOM中删除节点变得容易。但是,如何从给定的jQuery对象中删除DOM元素?

最佳答案

如果要谈论从jQuery对象中删除节点,请使用filternot函数。 See here for more

如何使用filter:

var ps = $('p');

//Removes all elements from the set of matched elements that do
//not match the specified function.
ps = ps.filter(function() {
  //return true to keep it, false to discard it
  //the logic is up to you.
});

要么
var ps = $('p');

//Removes all elements from the set of matched elements that
//do not match the specified expression(s).
ps = ps.filter('.selector');

如何使用not:
var ps = $('p');

//Removes elements matching the specified expression
//from the set of matched elements.
ps = ps.not('.selector');

10-08 08:43
查看更多