jquery - 更改兄弟节点为标签的文本节点

标签 jquery html css

这是我的 html:

<div id="ref">
   <p>.....</p>
   <p>.....</p>
   abcd
</div>

我想将“abcd”文本更改为其他一些文本,例如“wxyz”。 我如何遍历该文本,尤其是在 jquery 中?

编辑 1:

我是笼统地问这个问题,没有必要总是“abcd”或“wxyz”

最佳答案

$("#ref").contents().last()[0].nodeValue = "wyxz";

http://jsfiddle.net/rWss5/

关于jquery - 更改兄弟节点为标签的文本节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948356/

相关文章:

html - 我不能使用 :first-child selector in this scenario?

html - 将响应图像居中

css - 子div不占父div的高度

html - 为什么 font-size 会移动我的父 div?

jquery - 如何检查数组是否是多维的? (jQuery)

javascript - 如何创建纯色填充的 html 条形图?

javascript - 如何动态显示图像横向和纵向

css - 使用剑道网格中的属性格式化字符串

javascript - 使用 capybara ,我无法从 href 读取自定义数据属性

javascript - 当页面只来回穿过某个分辨率一次时如何触发刷新/重新加载