I have an html inspect code as shown below:
<time datetime="07:05 13-06-2020" data-area="ab">13 June <span>07:05</span></time>
The above html inspect prints the following on webpage:
13 June
What I want to achieve is instead of 13 June, it should display 13 Juin on page load.
This is what I have tried but its replacing the 13 June with Juin.
$(document).ready(function(){
$("time").replaceWith("Juin");
});
I have an html inspect code as shown below:
<time datetime="07:05 13-06-2020" data-area="ab">13 June <span>07:05</span></time>
The above html inspect prints the following on webpage:
13 June
What I want to achieve is instead of 13 June, it should display 13 Juin on page load.
This is what I have tried but its replacing the 13 June with Juin.
$(document).ready(function(){
$("time").replaceWith("Juin");
});
Share
Improve this question
asked Jun 14, 2020 at 2:07
user1950349user1950349
5,15620 gold badges73 silver badges128 bronze badges
0
4 Answers
Reset to default 3You are replacing the entire time
element by using .replaceWith
. Instead, you need to change the inner HTML of the time
tag:
$(document).ready(function() {
$("time").html($("time").html().replace('June', 'Juin'));
});
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<time datetime="07:05 13-06-2020" data-area="ab">13 June <span>07:05</span></time>
One more way how you can do that
window.onload = function(){
var a = document.getElementsByTagName('time')[0];
a.innerHTML = a.innerHTML.replace(/June/,'Juin');
};
<time datetime="07:05 13-06-2020" data-area="ab">13 June <span>07:05</span></time>
Try this:
Demo: https://jsfiddle/o60x7q83/
$(document).ready(function(){
$("time").html($("time").html().replace('June', 'Juin'));
});
low explained about "Javascript" in Jquery is other syntax onload can load on body as reference to this function
(function(e) {
e.preventDefault;
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
document.getElementById("txt").innerHTML = h + ":" + m + ":" + s;
var t = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
}())