克隆每个元素后添加换行符

发布于 2024-12-22 04:07:39 字数 476 浏览 5 评论 0原文

$('.footnote').clone().appendTo('#allfootnotes').append('<br>');

我在整个页面中有一堆 .footnote 元素,在页面底部我想列出页面上的所有脚注。因此每个脚注都会被克隆到#allfootnotes。我试图在 #allfootnotes 元素中的每个 .footnote 之后放置一个换行符,这样它们就不会混在一起。

一旦将每个 .footnote 克隆到 #allfootnotes 后,如何在每个 .footnote 之后应用换行符?

这是最好的方法吗?在每个 .footnote 中有 2 个 span 标签,一个用于标题,一个用于脚注内容(不知道这是否重要)。

$('.footnote').clone().appendTo('#allfootnotes').append('<br>');

I have a bunch of .footnote elements all through the page, at the bottom of the page I want to list all of the footnotes on the page. So each footnote will be cloned to #allfootnotes. I'm trying to place a line break after each .footnote in the #allfootnotes element, so they're not all jumbled together.

How would I apply the line break after each .footnote once it's been cloned to #allfootnotes?

And is this the best way to do it? In each .footnote there's 2 span tags, one for the title, and one for the footnote content(don't know if that matters or not).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无法回应 2024-12-29 04:07:39

听起来您可以使用 CSS 来执行此操作,

#allfootnotes .footnote {
  margin-bottom: 10px;      
}

具体取决于您的情况,您可能需要使用 display: block; 将 .footnote 设为块级元素

It sounds like you could use CSS to do this

#allfootnotes .footnote {
  margin-bottom: 10px;      
}

Depending on your situation you may need to make .footnote a block level element with display: block;

执笔绘流年 2024-12-29 04:07:39

DEMO

$('.footnote').clone().appendTo('#allfootnotes').after('<br>');

如果您使用 XHTML,则应该是 <代码>

DEMO

$('.footnote').clone().appendTo('#allfootnotes').after('<br>');

If you use XHTML than it should be <br />

在巴黎塔顶看东京樱花 2024-12-29 04:07:39
var allFootNotes = $('#allfootnotes');
$('.footnote').each(function(){
     $(this).clone().add('<br/>').appendTo(allFootNotes);
});

如果有如您所说的那么多脚注,缓存 $('#allfootnotes') 将减少浏览器的负载。

希望这有帮助

var allFootNotes = $('#allfootnotes');
$('.footnote').each(function(){
     $(this).clone().add('<br/>').appendTo(allFootNotes);
});

If there are as many foot notes as you say cacheing your $('#allfootnotes') will decrease load on the browser.

Hope this helps

美胚控场 2024-12-29 04:07:39
$('.footnote').each(function() {
    $(this).clone().add('<br/>').appendTo('#allfootnotes');
});

编辑请参阅 roXon 的答案。这比自己迭代脚注要干净得多。

$('.footnote').each(function() {
    $(this).clone().add('<br/>').appendTo('#allfootnotes');
});

EDIT Please see roXon's answer. It's way cleaner than iterating over footnotes yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文