使用jquery更改文本和html

时间:2013-09-23 07:23:23

标签: jquery

在HTML中我有

code exchange org <sup>®</sup>

我需要删除该空间之后的空间。像这样做

code exchange org<sup>®</sup>

我正在使用的jquery

$(div).each(function(){

$(this).text("org <sup>").replace("org<sup>");


});

6 个答案:

答案 0 :(得分:2)

演示http://jsfiddle.net/krasimir/yFA4S/

$("div").each(function(){
    $(this).html($(this).html().replace("org <sup>", "org<sup>"));
});

答案 1 :(得分:1)

尝试

$('div').each(function(){
    this.innerHTML = this.innerHTML.replace(' <sup>','<sup>');
});

$('div').each(function(){
    $(this).html( $(this).html().replace(' <sup>','<sup>'));
});

参考

.innerHTML

.replace()

答案 2 :(得分:1)

这应该这样做:$(this).text( $(this).text().replace("group <","group<") ); 我希望我是第一个,反正希望我能帮助你。

答案 3 :(得分:1)

您没有正确使用replace方法

他们这个

$(div).each(function(){    
   this.innerHTML = this.innerHTML.replace('org <sup>','org<sup>');    
});

答案 4 :(得分:1)

你需要像这样分配你改变的值

$(your div here).each(function(){

this.innerHTML = this.innerHTML.replace(' <sup>','<sup>');

});

答案 5 :(得分:0)

尝试

$('div sup').each(function () {
    var prev = this.previousSibling;
    if (prev && prev.nodeType == 3) {
        prev.textContent = $.trim(prev.textContent)
    }
});

演示:Fiddle