开发者

JQuery .html() ignoring Table Structure

I have a html table

<table class="items">
<tr>
<td>test1</td>
<td>test2</td>
<td>test3</td>
</tr>
</table>

I want t开发者_开发问答o get its inner html through class in JQuery

$(".items").html();

this is getting table content but not the whole styling. any solution?


The styling is not stored in your HTML, it's in your CSS file.

If, for example, you are applying your CSS styles based on the table's class name (in this case: items), you'll have to give the other table (where you're dropping the tr's into) the same class name.


$(".items").html(); returns only inner html of this element. If you want to get this element html.

You need to $(".items").parent().html(); but only if your table is only one element in your parent, otherwise you need to wrap your table in div for example.

Also here is another cheat: How to get full html string including the selected element itself with jQuery's $.html(), but I dont like it because to getting html we need to clone the element. Who knows, element can be too big.


I'm not sure what you mean by 'styling'? But jQuery will only return the inner contents of the table HTML, if you want to get the entire HTML try one of the solutions from this question -

Get selected element's outer HTML

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜