admin管理员组文章数量:1022641
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.
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.
本文标签: javascriptHow remove a specific string from an element39s text using jQueryStack Overflow
版权声明:本文标题:javascript - How remove a specific string from an element's text using jQuery? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745520789a2154305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论