jquery - 如何更改 jquery text() 的样式?

标签 jquery css

假设我有:

<span id="spanny"><strong>some default text</strong></span>

我得到:一些默认文本

然后我打电话:

$("#spanny").text("<strong>new text</strong>");

我得到:

<strong>new text</strong>

我想要什么:

新文本

如何设置文本样式以具有“STRONG”属性?

最佳答案

使用html代替text:

$("#spanny").html("<strong>new text</strong>");

html用于设置 HTML 内容,而 text将转义字符串。

关于jquery - 如何更改 jquery text() 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15141703/

相关文章:

jquery - 更改元素位置后的 CSS 样式

jquery - 在使用 jQuery 的 prop 方法时,如何使用 Capybara 测试表单元素是否被禁用?

javascript - Jqgrid - 如何更改禁用/灰色文本颜色

jquery-ui - 多行多级列表

javascript - 屏幕上的完整横幅宽度

PHP session 未在 css 文件中读取

HTML 电子邮件 : put transparent background color on image and text on it

javascript - 在 rails 3.2.2 中使用 $.ajax() 异步获取数据

jquery - knockout : How to delete multiple table row using check on knockoutJS?

css - 悬停后将光标放在输入字段中