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
1 Answer
Reset to default 7You 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.