Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery Get元素中没有一个';谁的孩子?_Javascript_Jquery_Dom Manipulation_Removechild - Fatal编程技术网

Javascript JQuery Get元素中没有一个';谁的孩子?

Javascript JQuery Get元素中没有一个';谁的孩子?,javascript,jquery,dom-manipulation,removechild,Javascript,Jquery,Dom Manipulation,Removechild,是否可以在JQuery中执行此操作: <div> <h2>Test test</h2> <span class="test"> HELOOOO </span> </div> 测试 HELOOOO 如果我将上述代码存储在variable(例如:var content)中,是否有任何函数可以调用,以返回没有特定元素的原始内容?类似于var content=content.r

是否可以在JQuery中执行此操作:

<div>
   <h2>Test test</h2>
      <span class="test">
          HELOOOO
      </span>
</div>

测试
HELOOOO
如果我将上述代码存储在variable(例如:var content)中,是否有任何函数可以调用,以返回没有特定元素的原始内容?类似于var content=content.remove('.test')的内容


测试

这应该是返回值吗?

这个答案应该有效

$(content).find('.test').remove().end()[0].outerHTML
仅在您发布的情况下有效,而在由于
[0]
而存在多个“根”元素的情况下,仅选择第一个

如果将内容包装到一个根元素中,那么就更容易了,只需使用jQuery中的
html()

var $template = $('<div><h1>A</h1>B<h1>A</h1>B</div><div><h1>A</h1>B<h1>A</h1>B</div>');
var filtered = $("<div>").append($template.find("h1").remove().end()).html();

alert(filtered);
var$template=$('ababababab');
var filtered=$(“”).append($template.find(“h1”).remove().end()).html();
警报(过滤);

var $template = $('<div><h1>A</h1>B<h1>A</h1>B</div><div><h1>A</h1>B<h1>A</h1>B</div>');
var filtered = $("<div>").append($template.find("h1").remove().end()).html();

alert(filtered);