/    Sign up×
Community /Pin to ProfileBookmark

Dynamic links without using document.links array

Is it possible in Javascript to refer and change the links without referring to document.links array.

For example:

Step 1:
document.write(‘<a href=”sth.htm”>Click me !!!</a>’);

Step 2:
When someone clicks on an image the links attribute href changes to “bye.htm”. I wouldn’t like to use the following code:
document.links[0].href=”bye.htm”

How can I refer to the link with a name instead of links array.
For example:
document.mylink.href=”bye.htm”;

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 18.2005 — Using the links array is the easiest:

document.links['anchorName'].href
Copy linkTweet thisAlerts:
@CharlesApr 18.2005 — You could use the Document Object Model to traverse the document tree or you could just give the link an id and use [font=monospace]document.getElementById ('id').href[/font]
Copy linkTweet thisAlerts:
@JavaFrekauthorApr 19.2005 — Thx Charles. Your solution was the best.
×

Success!

Help @JavaFrek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...