473,387 Members | 1,431 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,387 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 27622
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.