473,756 Members | 8,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change link text

I need to change all the links on my site that say "more information"
to something else. Unfortunately I don't have access to change the
component that places these links in the first place, so I need to use
Javascript at runtime to go through, find each instance of a link with
the above string and change it. Is there a good cross-browser way of
achieving this? Is HTMLAnchorEleme nt a good place to start?

Thanks

Nov 23 '05 #1
5 5739

co*****@nelsonf ord.net wrote:
I need to change all the links on my site that say "more information"
to something else. Unfortunately I don't have access to change the
component that places these links in the first place, so I need to use
Javascript at runtime to go through, find each instance of a link with
the above string and change it. Is there a good cross-browser way of
achieving this? Is HTMLAnchorEleme nt a good place to start?

Thanks


This should give you a start. It's very simple and not very
comprehensive. This sample really works in the case such as:

<a href = "uri">more information</a>

sample script:

var anchors = document.getEle mentsByTagName( "a");

for(var i = 0; i < anchors.length; ++i)
{
if(anchors[i].firstChild.dat a == "more information")
{
anchors[i].replaceChild(d ocument.createT extNode("new info"),
anchors[i].firstChild);
}
}

Nov 23 '05 #2
web.dev a écrit :
co*****@nelsonf ord.net wrote:
I need to change all the links on my site that say "more information"
to something else. Unfortunately I don't have access to change the
component that places these links in the first place, so I need to use
Javascript at runtime to go through, find each instance of a link with
the above string and change it. Is there a good cross-browser way of
achieving this? Is HTMLAnchorEleme nt a good place to start?

Thanks

This should give you a start. It's very simple and not very
comprehensive. This sample really works in the case such as:

<a href = "uri">more information</a>

sample script:

var anchors = document.getEle mentsByTagName( "a");


Also
var arrLinks = document.links;
http://www.w3.org/TR/DOM-Level-2-HTM...tml#ID-7068919

for(var i = 0; i < anchors.length; ++i)
it should be i++, not ++i
{
if(anchors[i].firstChild.dat a == "more information")
{
anchors[i].replaceChild(d ocument.createT extNode("new info"),
anchors[i].firstChild);
}
}


for(var LinkIterator = 0; LinkIterator < arrLinks.length ; LinkIterator++)
{
if(arrLinks[LinkIterator].firstChild.nod eValue == "more information")
{
arrLinks[LinkIterator].firstChild.nod eValue = "new info";
};
};

Gérard
--
remove blah to email me
Nov 23 '05 #3
Gérard Talbot wrote:
web.dev a écrit :

<snip>
for(var i = 0; i < anchors.length; ++i)


it should be i++, not ++i

<snip>

There is no should here. In context pre-increment and post-increment
will have the same outcome, and pre-increment is theoretically the more
efficient operator.

Richard.
Nov 23 '05 #4
Thanks all, for your help. I'm getting an object required error on this
line:

if(arrLinks[LinkIterator].firstChild.nod eValue == "more information")

I've added this code to the bottom of my page. Any ideas?

Nov 25 '05 #5
test

Nov 25 '05 #6

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

Similar topics

3
17092
by: Matt Adams | last post by:
As well known I could specify the text color in the body tag like: <BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE> What I want to achieve now is that always (!) the text of the last visited link and the text of the link under the cursor are red. All other links should be white. The problem with the construction above is that a visited link remains for the rest of the session red regardless wether it was visited 17 clicks back in...
14
2518
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and change its text contents from a link elsewhere in the page? I have a rought idea that I'll need something like 'id' in my <td> tags but while I have a greater understanding of server-side programming langauges like PHP, javascript is still very new...
5
35240
by: Matt | last post by:
I created 3 hyperlinks, when the user click each link, it will change the color of the text of a link. For example, when user clicks Link1, text Link1 will become red color, but Link2 and Link3 unchange. Here's my attempts, any ideas?? <script language="javascript"> function changecolor (i) { document.i.fontcolor = red; }
3
7158
by: bigoxygen | last post by:
Hi. I have a list that is similar to this: -Evaluation +test +test -Students +test I would like to change the "-" bullet only, but I cannot. My
4
2635
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an QA tested for a new year release. I don't think that going to prove practical, but there is no harm in trying :) and some serious family commitments. But it has to be done soon so this is stage one. Mike Winter provided an extensive list of...
3
3390
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make navigation buttons. I'm using the tutorial I found at this site as a basis for it. http://www.mako4css.com/TFonts.htm
6
3196
by: Karl | last post by:
Hi, Ok so on a given page I have 4 text links: see it in black see it in blue see it in red see it in green using the standard swap image behavior, clicking on one of the above links
7
2182
by: Tim Rogers | last post by:
Hi folks, this is a resolution-detect script that I used on a site. As you can see it is designed to detect when the screen resolution falls below a certain level then load an alternative style sheet HOWEVER, is it possible to make a change to the code that will not only make it respond to windows with widths of less than 800 pixels but ALSO heights of less than 600 pixels. I'm a complete novice when it comes to .js so and help would...
5
3067
by: _Who | last post by:
I spent all day yesterday trying different things. Something has happened so I can't change font size. I have a table and in the first cell I have only text. I tried using the cell's Style to change the font size. I tried using the cell's attribute to change the font size. I tried adding a paragraph element and doing the above to it. Removed all font sizes from Body, Table...
6
4519
by: gavy7210 | last post by:
hello i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5.. i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error is displayed using the <ul> tag and <html:errors> in the jsp. in the from class a vaidate method creates an actionerrors object adds all the errors to it and finally returns it. the ids are linked in messageresources.properties and appropriate...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.