1

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");
});
0

4 Answers 4

3

You 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.com/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>

Sign up to request clarification or add additional context in comments.

1 Comment

hi, I have one more question. It's not similar. I am wondering if you can have a look. What I want to achieve is when one user (UserA) is logged in and another user (UserB) tries to login at the same time then UserA should not be allowed to save the form meaning we are revoking the write access for UserA.
2

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>

Comments

1

Try this:

Demo: https://jsfiddle.net/o60x7q83/

$(document).ready(function(){ 
    $("time").html($("time").html().replace('June', 'Juin'));
});

Comments

1

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;
 }
}())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.