簡體   English   中英

如何在文章中的每個表之前添加帶有類的div標簽,並在表關閉標簽后使用javascript添加div關閉標簽

[英]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> 我該怎么做。

您將jQuery作為標簽,因此假設您已經擁有jQuery,則可以使用wrap()函數。

要包裝所有表,您可以做

$('table').wrap('<div class=""></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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM