I want to format this date: <div id="date">23/05/2013</div>
.
First I want to split the string at the first /
and have the rest in the next line. Next, I’d like to surround the first part in a <span>
tag, as follows:
<div id="date">
<span>23</span>
05/2013</div>
23
05/2013
What I did:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="date">23/05/2013</div>
<script type="text/javascript">
$(document).ready(function() {
$("#date").text().substring(0, 2) + '<br />';
});
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…