Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change span text? [duplicate]

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

like image 225
user1053018 Avatar asked Nov 18 '11 02:11

user1053018


People also ask

How do I change text in a span?

Use the textContent property to change the text of a span element, e.g. span. textContent = 'Replacement text' . The textContent property will set the text of the span to the provided string, replacing any of the existing content.

How do you text the span of an element?

Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants.

How do you change text in HTML?

To change the text font in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-family, font-size, font-style, etc. HTML5 do not support the <font> tag, so the CSS style is used to change font.

What is a span of text?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.


2 Answers

document.getElementById("serverTime").innerHTML = ...; 
like image 166
SLaks Avatar answered Oct 01 '22 01:10

SLaks


Replace whatever is in the address bar with this:

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

Example.

like image 43
Purag Avatar answered Oct 01 '22 03:10

Purag