How can this section of js be changed from onclick execution to onload execution?

The date string in

li: 2018-10-12, etc., after many times, the values are all taken out with js and modified to: 2018-10 "strong" 12 "/ strong", and finally the modified results are rewritten into the corresponding original tag, so that I can use css control to do a design style. I can only patchwork so that I can modify it after onclick. I don"t know how to change it automatically without mouse trigger.

<ul id="news">
    <li><p class="time">2018-10-12

</li> <li><p class="time">2017-08-03

</li> </ul> <script> //:replacePos(, , ""); function replacePos(strObj, pos, replacetext) { var str = strObj.substr(0, pos-1) + replacetext + strObj.substring(pos, strObj.length); return str; } // function picnewsTime() { var obj = $(".time");//JQclasstime for(var i = 0; i < obj.length; iPP) { (function(arg){ var txt = obj[arg].textContent || obj[arg].innerText;// var newhtml = replacePos(txt, 8, "<strong>");//replacePos()"-" <strong> newhtml += "</strong>";//</strong> //onclick obj[arg].onclick = function() { $(this).html(newhtml);// } })(i);//i } } picnewsTime(); </script>
Sep.05,2021

you are just a matter of code order. You are used to putting < script > on

    .

    put

    obj[arg].onclick = function() {
        $(this).html(newhtml);//
    }
    Change

    to

    $(obj[arg]).html(newhtml);

    and

    picnewsTime();
    Change

    to

    //DOM<ul>
    $(function(){
        picnewsTime();
    });

              obj[arg].onclick = function() {
                    $(this).html(newhtml);//
                }

    becomes

    obj[arg].html(newhtml)
    Is there a problem with

    ? Why not click


    Why don't you render it as 2018-10 12 in the first place

    ?
Menu