[英]How I add div tag with class before every table in the article and add div closeing tag after table closing tag with javascript
我想使用JavaScript動態地在<table>
<div class="">
之前添加<div class="">
,並在</table>
之后添加</table>
</div>
。 我該怎么做。
您正在尋找這個:
$(document).ready(function(){ //before added console.log($('.main-content').html()); $("button").click(function(){ $("table").wrap("<div class='AddedTag'></div>"); //after added console.log($('.main-content').html()); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="main-content"> <table> <tr> <th>Test table col</th> </tr> </table> </div> <button>Click to add</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.