javascript - How remove a specific string from an element's text using jQuery? - Stack Overflow

I want to remove 12:00:00 AM from following string.<div class="modal-body"><p>11

I want to remove 12:00:00 AM from following string.

<div class="modal-body">
    <p>1/11/2016 12:00:00 AM - 1/13/2016 12:00:00 AM</p>
</div>

The results should be:

1/11/2016 - 1/13/2016

How can I remove just the 12:00:00 AM from plete string all occurrences of it.

$('.modal-body > p').text().remove("12:00:00 AM");

I want to remove 12:00:00 AM from following string.

<div class="modal-body">
    <p>1/11/2016 12:00:00 AM - 1/13/2016 12:00:00 AM</p>
</div>

The results should be:

1/11/2016 - 1/13/2016

How can I remove just the 12:00:00 AM from plete string all occurrences of it.

$('.modal-body > p').text().remove("12:00:00 AM");
Share Improve this question edited Dec 1, 2015 at 0:30 Josh Crozier 242k56 gold badges400 silver badges313 bronze badges asked Nov 30, 2015 at 17:15 Aamir ShahzadAamir Shahzad 6,8348 gold badges49 silver badges72 bronze badges 2
  • If you are getting these time stamps from a database you may want to format them using either SQL or your server-side script. – PeterKA Commented Nov 30, 2015 at 17:27
  • @PeterKA you are right I need a quick fix for now. I will ask a separate question for that. Thanks a lot – Aamir Shahzad Commented Nov 30, 2015 at 17:36
Add a ment  | 

1 Answer 1

Reset to default 7

You could use the .replace() method:

Example Here

$('.modal-body > p').text(function () {
    return $(this).text().replace(/12:00:00 AM/g, '');
});

Result:

<div class="modal-body">
    <p>1/11/2016  - 1/13/2016</p>
</div>

If you only want to replace the first occurrence, just remove the g flag.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745520789a4631250.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信