需要从动态页面中删除内容

时间:2012-06-02 14:15:51

标签: jquery html

我需要删除300美元,任何想法?价格动态上涨

<h3>
     $300.00 <br><span>$500.00</span> 
</h3>

这是我的jQuery代码,我知道它错误的代码

$('.price>h3 ').contents().remove();

3 个答案:

答案 0 :(得分:2)

$('h3').contents(':not(span)').remove();

<强> DEMO

$('.price > h3').text(function(index, text) {
   return text.replace(/300.00/,'').replace(/\$/,'');
});

<强> DEMO

$('.price > h3').html(function(index, text) {
   return $('span');
});

<强> DEMO

答案 1 :(得分:1)

如果您只想要跨度:

$('h3').html(function( i, old){
    return $(old).filter('span')
})

演示:http://jsfiddle.net/dr7CC/

答案 2 :(得分:1)

$(function(){
  var children = $('h3').children();
  $('h3').html('');
  $('h3').append(children);
});