/    Sign up×
Community /Pin to ProfileBookmark

Accessing link’s HTML text

Hi,

I need to know that how can I access the text that appears on a HTML page for a hyperlink. (i.e. I need to access “My Link” in the example below) Using the text property of the anchor object doesn’t work if I have created a link on my page as

<a href=”javascript:void(0);”>My Link</a>

However, creating a link as <a href=”javascript:void(0);” text=”some text”>My Link</a> gives me “some text”. Can anyone help me on this?

Thanks in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJun 27.2005 — Here's a few ways.

<a href="#null" onclick="alert(this.innerHTML)">My Link</a>

Or

<a id="link1" href="#null" onclick="alert(document.getElementById('link1').innerHTML)">My Link 2</a>

Or

<script type="text/javscript">

<!--

function alertMe1(obj){

alert(obj.innerHTML)

}

function alertMe2(id){

alert(document.getElementById(id).innerHTML)

}

//-->

</script>

<a href="#null" onclick="alertMe1(this)">My Link 3</a>

<a id="link4a" href="#null" onclick="alertMe2(this.id)">My Link 4a</a>

<a id="link4b" href="#null" onclick="alertMe2(this.id)">My Link 4b</a>
Copy linkTweet thisAlerts:
@Nitint_KhareauthorJun 27.2005 — Thanks a lot. It was something that I was really looking for.
Copy linkTweet thisAlerts:
@google_archive1Jul 27.2005 — indexed JUL 27 2005 10:41:57
×

Success!

Help @Nitint_Khare 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.17,
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,
)...