开发者

jquery .html function remove part of a text within a div

in my question one suggested to do:

$(".entry").html(function(i, htm){
   return htm.spli开发者_如何学Ct("-")[0];
});

To remove Approuved - Expire May 18 th 2012 but this remove

Source: SuperSite also and i would like to keep the source

<div class="entry">
Published May 18th 2011 - Approuved - Expire May 18 th 2012<br>Source: SuperSite
</div>

I would like to remove Approuved - Expire May 18 th 2012

So the result would be:

<div class="entry">
    Published May 18th 2011 <br>Source: SuperSite
    </div>


$(".entry").html(function(i, htm){
  var retStr = htm.split("-")[0]
  return retStr+htm.split("<br>")[1];
});

You return only what is placed before the first '-'. You have to add what it's placed after the <br> tag. Code snippet is only for give you an idea. It's a little bit dirty but you can start from it.


May ne you might try:

return htm.replace(/-[^<]+?/, '');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜