473,216 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Changing anchor text

Hi guys,

I would like to change the text in an anchor.

es.

from
<a id="idanchor">oldtext</a>

to
<a id="idanchor">newtext</a>
I found that under Explorer, it is possible to do it as:
anchor = document.getElementById('idanchor');
anchor.innerText = "newtext";

Under Mozilla, such anchor property is called "text", but if I write:
anchor = document.getElementById('idanchor');
anchor.text = "newtext";

the Javascript console gives me the following error:
"setting a property that has only a getter"

it looks like the text property can only be read, but not written.
Do you know any other way to change the text anchor also under Mozilla?

Cheers

Daniele
Jul 23 '05 #1
6 27612
Daniele Baroncelli schrieb:
anchor = document.getElementById('idanchor');
anchor.innerText = "newtext";


anchor.innerHTML = "newtext";
HTML formating also possible: "new<b>text<\/b>"

Daniel
Jul 23 '05 #2
On Thu, 16 Dec 2004 13:05:57 +0100, Daniel Kirsch
<Iw*****************@gmx.de> wrote:

[snip]
anchor.innerHTML = "newtext";
Though I've found text-only replacement can be much quicker using a
DOM-only approach:

anchor.firstChild.data = 'new text';

or

anchor.replaceChild(document.createTextNode('new text'),
anchor.firstChild)
HTML formating also possible: "new<b>text<\/b>"


Presentational elements should[1] be avoided.

Mike
[1] Elements such as B and I are not deprecated (U is, but I think they
all should be), but their use is formally discouraged.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Michael Winter schrieb:
Though I've found text-only replacement can be much quicker using a
DOM-only approach:

anchor.firstChild.data = 'new text';

or

anchor.replaceChild(document.createTextNode('new text'),
anchor.firstChild)


Yes. If you can be sure there is only one child element in your a
element. Which isn't the case if there is a comment and some text or
just a simple <br> with a space before and/or after. Speed migh be an
argument if you do *a lot* of replacements.

HTML formating also possible: "new<b>text<\/b>"


Presentational elements should[1] be avoided.


Of course. That should just show the flexibility of innerHTML which
isn't part of the w3c DOM but is implemented in all relevant browser.

Daniel
Jul 23 '05 #4
JRS: In article <opsi3qu5pwx13kvk@atlantis>, dated Thu, 16 Dec 2004
13:05:24, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :
[1] Elements such as B and I are not deprecated (U is, but I think they
all should be), but their use is formally discouraged.


In some fields of work, standard conventions explicitly call for italics
to be used, and maybe bold also/instead.

While a non-GUI browser will have to do whatever it can, the appearance
of a GUI rendition of such material should not be determined by what
<em> or <strong> or whatever the browser has been set to produce. If
the user's CSS maps italic to purple, that's his problem.

See, for example, SUNAMCO 87-1 == IUPAP-25 (which had formal authority
over TB-L when the Web started!). URL not known.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk / ??*********@physics.org
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Jul 23 '05 #5
Daniel Kirsch wrote:
Michael Winter schrieb:
Though I've found text-only replacement can be much quicker using a
DOM-only approach:

anchor.firstChild.data = 'new text';

or

anchor.replaceChild(document.createTextNode('new text'),
anchor.firstChild)

Yes. If you can be sure there is only one child element in your a
element. Which isn't the case if there is a comment and some text or
just a simple <br> with a space before and/or after. Speed migh be an
argument if you do *a lot* of replacements.


The innerHTML also has that problem. If you replace its innerHTML, then
you wipe out what was there. You can append to the beginning or the end,
quite easily, with innerHMTL. You can also add in the middle with only a
trivial amount of extra work.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
On Thu, 16 Dec 2004 23:00:50 +0000, Dr John Stockton
<sp**@merlyn.demon.co.uk> wrote:
JRS: In article <opsi3qu5pwx13kvk@atlantis>, dated Thu, 16 Dec 2004
13:05:24, seen in news:comp.lang.javascript, Michael Winter
<M.******@blueyonder.co.invalid> posted :
[1] Elements such as B and I are not deprecated (U is, but I think they
all should be), but their use is formally discouraged.


In some fields of work, standard conventions explicitly call for italics
to be used, and maybe bold also/instead.


So? A truly semantic document would mark-up what was inferred by that
presentation. Granted, it would be bulky with HTML (lots of SPAN elements
with classes), but then again HTML isn't really geared towards displaying
mathematical content.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kenny | last post by:
I have been trying to write a script that will increase the size of and image when you mouse over it, and decrease it to original size, when you mouse out. After a couple of attempts, this is what...
8
by: Margaret MacDonald | last post by:
I'm a js novice trying to teach myself. I'm using Flanagan's 'Javascript, the definitive guide' from O'Reilly as a text. But either I'm dopier than usual or its layout doesn't match my learning...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
1
by: Nathan Sokalski | last post by:
I am using the ImageUrl property of the Hyperlink control to create a graphical Hyperlink. However, I want to change the size of the image I am using, but the generated HTML places the width/height...
6
by: Richard Brown | last post by:
Ok, I celebrate and rejoice in the Anchor property. So wonderful compared to the horrible 'resize' code I had to write in VB6, there is just no end to the wonders of VB.NET..... uh, ok..... BUT......
15
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px;...
1
by: JB | last post by:
I have a set of links that are currently images that when the person rolls over them, they change color. Essentially the image is a box where the background is brown and the text is blue. When the...
3
by: Joseph Gruber | last post by:
Hi all -- I have two questions. First, I'm adding a control to my form at runtime and the control/form seems to ignore the anchor property of the runtime control. Any idea how I can get a...
8
by: azjudd | last post by:
Thank you in advance for your help on this one. I'm using named anchor tags on a FAQ page with questions listed at the top and answers below; a standard jump-to feature. However, anytime an anchor...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.