简体   繁体   中英

Change a part of the span text using a bookmarklet javascript?

recently I've asked a question on how to change a span's text via javascript ,

and the answer was

javascript:void(document.getElementById("serverTime").innerHTML = "...");

Now I want to change this span : <span id="serverTime">5:46:40</span>

into this one <span id="serverTime">3:46:40</span>

and no , not just editing the whole span and using the previous code , just editing a part of the span .

If that's possible though , I don't have an idea.

If you just need to change the span s text, then you can use replace:

javascript: (function (doc) {
    var sTime = doc.getElementById("serverTime"); 
    sTime.innerHTML = sTime.innerHTML.replace('5', '3');
})(document); // Remove spaces when bookmarking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM