/    Sign up×
Community /Pin to ProfileBookmark

Parsing & changing href value

Hi all,

I’m struggling with this little problem of parsing the href and then changing it. So for example, I have a href value of ‘http://www.mysite.com/about/link.html‘ and what I need to do is change that to ‘http://www.mysite.com/about/new_link.html

Can someone please help me with this or point me to a script that does that.

Thanks in advance!!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 18.2005 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>change link</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
<!--
function changeLink() {
document.getElementById('xxxx').href='http://www.mysite.com/about/new_link.html';
document.getElementById('xxxx').firstChild.data='new_link';
}
//-->
</script>

</head>
<body>
<div>
<a id="xxxx" href="http://www.mysite.com/about/link.html">link</a>
</div>
<div>
<button type="button" onclick="changeLink();">change link</button>
</div>
</body>
</html>
Copy linkTweet thisAlerts:
@kieranmobrienauthorAug 18.2005 — Fang,

Thanks for the script, but it actually replaces the text and not the actual href value. So I have my link <a href="http://www.mysite.com/about/link.html">A link</a> and what your script is doing is changing the text within the anchor tag i.e. <a href="http://www.mysite.com/about/link.html">new_link</a>. What I want it to do is change the href value so <a href="http://www.mysite.com/about/new_link.html">A link</a>

Cheers,

Kieran.
×

Success!

Help @kieranmobrien 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...