Javascript jquery从html方法中排除元素

Javascript jquery从html方法中排除元素,javascript,jquery,html,jquery-selectors,Javascript,Jquery,Html,Jquery Selectors,如何选择嵌套在下的所有元素(class=“excludeme”除外)的html 您可以使用这个微jQuery插件轻松获取元素的内容(文本或html),不包括/忽略特定选择器: $.fn.ignore=函数(sel){ 返回此.clone().find(sel | |“>*”).remove().end(); }; var notExcludeme=$(“.thewrapper”).ignore(“.excludeme”).html(); console.log(notExcludeme) 要

如何选择嵌套在
下的所有元素(class=“excludeme”除外)的html


您可以使用这个微jQuery插件轻松获取元素的内容(文本或html),不包括/忽略特定选择器:

$.fn.ignore=函数(sel){
返回此.clone().find(sel | |“>*”).remove().end();
};
var notExcludeme=$(“.thewrapper”).ignore(“.excludeme”).html();
console.log(notExcludeme)

要排除的某些内容。。。。
大量的内容和标签
要再次排除的某些内容。。。。
更多内容和标签

这里是另一个使用css选择器的解决方案。因为你试着用类似的方法做

$(函数(){
$('.thewrapper:not(.excludeme)).css('background','aqua');
});

要排除的某些内容。。。。
大量的内容和标签
要再次排除的某些内容。。。。
更多内容和标签

@RokoC.Buljan我认为这个问题与提供的链接不一样。这个问题的问题是选择没有一个元素的元素的子元素。@Mohammad确切地说,没有子元素
。excludeme
见下面的答案。完全按照要求去做。重复的问题要求使用
文本
(而不是
html
),但基本上原理是一样的。这太棒了。是的,这正是我问题的答案。很抱歉在发布之前没有注意到。非常感谢您的回答!!该代码适用于
.css()
,但不会返回正确的html。它只需要稍作调整。下面是一个示例,其中包含使用css选择器和jquery获取html的代码。
<div class="thewrapper">
  <div class="excludeme"> some content to exclude.... </div>

  <div class="whatever">
      <span> lots of content and tags </span>
  </div>

  <div class="excludeme"> some content to exclude again.... </div>

  <div class="whatever">
      <span> more content and tags </span>
  </div>     
var pagehtml = $("div[class^='thewrapper']:not(div[class^='excludeme']").html();
var pagehtml = $('div[class^="thewrapper"]').not('[class="excludeme"]').html();
var pagehtml = $("div.thewrapper:not(:has(div.excludeme))").html();
var pagehtml = $('div:not(".excludeme")').html();