从jQuery对象中删除项目

前端之家收集整理的这篇文章主要介绍了从jQuery对象中删除项目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
jQuery可以很容易地从DOM中删除节点。但是如何从jQuery对象中删除一些东西呢?

解决方法

如果你正在谈论从jQuery对象中删除节点,使用过滤器或不是函数See here for more

如何使用过滤器:

  1. var ps = $('p');
  2.  
  3. //Removes all elements from the set of matched elements that do
  4. //not match the specified function.
  5. ps = ps.filter(function() {
  6. //return true to keep it,false to discard it
  7. //the logic is up to you.
  8. });

要么

  1. var ps = $('p');
  2.  
  3. //Removes all elements from the set of matched elements that
  4. //do not match the specified expression(s).
  5. ps = ps.filter('.selector');

如何使用不:

  1. var ps = $('p');
  2.  
  3. //Removes elements matching the specified expression
  4. //from the set of matched elements.
  5. ps = ps.not('.selector');

猜你在找的jQuery相关文章