62

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 :\

0

2 Answers 2

151
document.getElementById("serverTime").innerHTML = ...;
Sign up to request clarification or add additional context in comments.

4 Comments

I tried it but it just opens a window with a white background and has the text I've entered..
In a bookmarklet, you need to add void(...) around it to suppress its return value.
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.
so it'd be javascript:void(document.getElementById("serverTime").innerHTML = ...); ?
8

Replace whatever is in the address bar with this:

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

Example.

2 Comments

I tried it but it just opens a window with a white background and has the text I've entered..
It worked for me: <button id="btnTest" onclick="document.getElementById('title').innerHTML='text here';" type="button">TEST</button>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.