Javascript 正在尝试删除嵌套标记
我有以下HTML: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>
<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());