I have the following div and i want to remove the time e.g. 12:30. What is the best way to do it? The content is dynamic. Here is a Fiddle i have tried
<div class="jsmatchdate">
11-08-2018 12:30
</div>
I have the following div and i want to remove the time e.g. 12:30. What is the best way to do it? The content is dynamic. Here is a Fiddle i have tried
<div class="jsmatchdate">
11-08-2018 12:30
</div>
With JQuery:
$('.jsmatchdate').text( function (_,txt) {
return txt.split(' ')[0];
})
Explanation: we splitted text by ' ' (empty character)
split function returns an array of ['11-08-2018', '12:30'] and we need the first part with index 0.
if you want to use jQuery then you could try the slice command.
$('.jsmatchdate').text(function (_,txt) {
return txt.slice(0, 11);
});
What this is doing is getting the text in the div and returning the desired length that you want, i.e. 11-08-2018