如何使用prependTo在标记表上添加类<div class="table-responsive">
?
我知道它是如何工作的,但是在TABLE标签之前没有把div放在类
之前答案 0 :(得分:3)
您可以使用wrap()
:
$( "table" ).wrap( "<div class='table-responsive'></div>" );
.table-responsive{
border:solid 1px red;
}
table, td{
border:solid 1px green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
</table>
答案 1 :(得分:0)
使用类“.table-responsive”将所有跨度预先添加到元素中(更多示例请查看.prepend()文档)
阅读更多详情Click
$( "span" ).prependTo( ".table-responsive" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="table-responsive">Hello</div>
<span>I have something to say... </span>
答案 2 :(得分:0)
$('.table-responsive').each(function() { $(this).attr("class", "Appended text." + $(this).attr("class") ); }); –
答案 3 :(得分:-1)
你正试图这样做。我是对的
<div class="table-responsive">
<table>
.......
</table>
</div>