开发者

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

开发者 https://www.devze.com 2023-03-11 09:39 出处:网络
in my question one suggested to do: $(\".entry\").html(function(i, htm){ return htm.spli开发者_如何学Ct(\"-\")[0];

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

精彩评论

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

关注公众号