如何使用jQuery附加HTML [英] How to append HTML using jQuery
本文介绍了如何使用jQuery附加HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用构建HTML元素
I am building up an HTML element using
$(this).html(' my html here');
我需要在此处使用不同的CSS添加许多元素.所以我想要的是我应该能够在这里附加另一个HTML
There are many elements I need to add here with different CSS. So what I want is I should be able to do append another HTML here
$(this).html(' my html here');
$(this).html.append(' another html here');
我该如何实现?
推荐答案
首先声明.
var html = "";
html += "<span class="spnBlack"> First Content </span>";
html += "<p class="pRed">Second Content</p>";
$(this).html(html);
然后在css文件中定义
And in css file define
.spnBlack
{
background-color: black;
}
.pRed
{
background-color: red;
}
请避免使用内联CSS.
Please avoid inline css.
这篇关于如何使用jQuery附加HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文