61

Possible Duplicate:
How do I change the text of a span element in javascript

Well, I've searched a lot for the answer to this, but still I couldn't find it. What I did find didn't work.

What I'm trying to do is, basically, using JavaScript: At the browser's bar, not via Greasemonkey or something else, edit a span's text .

This' the span that contains the text I want to edit:

<span id="serverTime">5:46:40</span>

The time within is just random, don't pay attention to it, it's what I want to edit using javascript..

I'm a newbie so yeah :\

Community
  • 1
  • 1
user1053018
  • 653
  • 1
  • 5
  • 5

2 Answers2

151
document.getElementById("serverTime").innerHTML = ...;
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I tried it but it just opens a window with a white background and has the text I've entered.. – user1053018 Nov 18 '11 at 03:04
  • 2
    In a bookmarklet, you need to add `void(...)` around it to suppress its return value. – SLaks Nov 18 '11 at 03:05
  • 1
    What's the need for it to be done via address bar? You could likely emulate the function it would have when used in the address bar with on-page javascript. – Purag Nov 18 '11 at 03:06
  • 2
    so it'd be javascript:void(document.getElementById("serverTime").innerHTML = ...); ? – user1053018 Nov 18 '11 at 03:06
8

Replace whatever is in the address bar with this:

javascript:document.getElementById('serverTime').innerHTML='[text here]';

Example.

Purag
  • 16,941
  • 4
  • 54
  • 75