Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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/78.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 正在尝试删除嵌套标记_Javascript_Jquery - Fatal编程技术网

Javascript 正在尝试删除嵌套标记

Javascript 正在尝试删除嵌套标记,javascript,jquery,Javascript,Jquery,我有以下HTML: <div class="item"> <div class="appIcon"> <img src="img/espn-hex2.png" alt="ESPN" /> </div> <div class="appDetails"> <h2>ESPN<small> SUMMER 2013, Bristol, CT</small>

我有以下HTML:

<div class="item">
     <div class="appIcon">
        <img src="img/espn-hex2.png" alt="ESPN" />
    </div>
    <div class="appDetails">
        <h2>ESPN<small> SUMMER 2013, Bristol, CT</small></h2>
        <p class="info">I was chosen for a Summer 2013 internship at ESPN, in Bristol, Connecticut. This was a dream come true opportunity for me since it combined my love of sports with my love of web development. I was part of the dotcom team which maintains the overall website. Specifically, I was part of the live events team. We handled creating pages for live games, home run derby, the Sportscenter mobile app, and many other things.</p>
        <br />
    </div>
</div>
然而,这并没有起作用。我在JS方面不是很先进,所以有人能给我指出正确的方向吗?

你的意思是:

var a = $(".item");
a.find("small").remove();
console.log(a.text());

演示::

您必须使用以下方法执行此操作:

HTML

更新的HTML:

您想做什么我无法理解问题也显示完整的html我看不到类中的任何元素item@EhsanSajjad我想从本质上创建一个h2标记的克隆,并从中删除小标记。因此,在本例中,我只需要获得“ESPN”。克隆是必要的,因为我不想从DOMit的幻灯片项目中删除小标记。包含所有信息。我会编辑这篇文章。太好了,谢谢!简单而干净的解决方案!
var a = $(".item");
a.find("small").remove();
console.log(a.text());
<h2>ESPN<small> SUMMER 2013, Bristol, CT</small></h2>
console.log($("h2").clone().find("small").remove().end().text());
<div class="item">
    <div class="appIcon">
        <img src="img/espn-hex2.png" alt="ESPN" />
    </div>
    <div class="appDetails">
         <h2>ESPN<small> SUMMER 2013, Bristol, CT</small></h2>

        <p class="info">I was chosen for a Summer 2013 internship at ESPN, in Bristol, Connecticut. This was a dream come true opportunity for me since it combined my love of sports with my love of web development. I was part of the dotcom team which maintains the overall website. Specifically, I was part of the live events team. We handled creating pages for live games, home run derby, the Sportscenter mobile app, and many other things.</p>
        <br />
    </div>
</div>
console.log($(".item").find("h2").clone().find("small").remove().end().text());