jQuery-如何将div添加到列表中的特定位置到具有相同类的现有项目列表(附加)

问题描述 投票:0回答:2

你好,我现有的物品清单。我想在列表的内部添加一个DIV,以使用引导扩展/折叠功能。

我想在10个项目之后添加div,并链接到列表中的最后一个位置。

谢谢!

<div id="list">
        <div class="item">some content</div>
        <div class="item">some content</div>
        <div class="item">some content</div>

        <!-- there is place for new DIV (after 3 items) -->
        <div class="item">some content</div>
        <div class="item">some content</div>
        <div class="item">some content</div>
        <div class="item">some content</div>
        <!-- there is place for end DIV -->

        <!-- there is place for LINK (last position) -->
        <a href="" class="collapse show">Show</a>
        <!-- there is place end LINK -->
</div>
jquery html css append
2个回答
0
投票

这样的事情?

$('#list').append('<div class="item">some content</div>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="list">
  <div class="item">some content</div>
  <div class="item">some content</div>
  <div class="item">some content</div>

  <!-- there is place for new DIV (after 3 items) -->
  <div class="item">some content</div>
  <div class="item">some content</div>
  <div class="item">some content</div>
  <div class="item">some content</div>
  <!-- there is place for end DIV -->

  <!-- there is place for LINK (last position) -->
  <a href="" class="collapse show">Show</a>
  <!-- there is place end LINK -->
</div>

0
投票
<div class="container">
  <h2>Araba</h2>
  <div class="inner">Merhaba</div>
  <div class="inner">Gule gule</div>
</div>

此代码也可用于添加所需的位置

$( "<p>Deneme</p>" ).append( ".inner" );
© www.soinside.com 2019 - 2024. All rights reserved.