jquery与之前爆发元素

时间:2017-05-05 04:53:09

标签: javascript jquery

我在这样的元素中有一个元素:

<div>
   <div class="contentBody">
      <img src="..." />
   </div>
</div>

我想打破contentBody的图像以获得此结果:

<div>
   <div class="contentBody">
   </div>
   <img src="..." />
   <div class="contentBody">
   </div>
</div>

我试过

$('img').before('</div>').after('<div class="contentBody">')

然而,这不起作用。我能做什么?感谢。

2 个答案:

答案 0 :(得分:1)

将图像附加到contentBody的父级,然后在另一个contentBody div之后插入:

$('img').appendTo($('.contentBody').parent()).after('<div class="contentBody">');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
   <div class="contentBody">
      <img src="..." />
   </div>
</div>

答案 1 :(得分:0)

SELECT *
FROM (
    SELECT Policy_ID
        ,max(Load_DATE) Load_DATE
        ,max(ENDORSEMENT#) ENDORSEMENT#
        ,max(SEQUENCE) SEQUENCE
        ,max(EXTRACTDATE) EXTRACTDATE
    FROM #TBL_POL t
    GROUP BY grouping SETS(Policy_ID, Load_DATE, ENDORSEMENT#, SEQUENCE, EXTRACTDATE)
    ) t4
WHERE Policy_ID IS NOT NULL

     drop table #TBL_POL
$('.contentBody img').unwrap();
$('img').before('<div class="contentBody"></div>');
$('img').after('<div class="contentBody"></div>');
.contentBody {
  background-color: red;
  height: 10px
}

  1. 使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <div class="contentBody"> <img src="..." /> </div> </div>
  2. 展开img
  3. 使用.unwrap().before()
  4. 添加div

    .after()

    UPDATE
    $('.contentBody img').before('<div class="contentBody"></div>');
    $('.contentBody img').after('<div class="contentBody"></div>');
    $('.contentBody img').unwrap();
    .contentBody {
      background-color: red;
      height: 10px
    }