28

This is a simple yes or no question (probably no), googling didn't seem to give me a straight answer. Say you have a link that is

<a href="www.stackoverflow.com">www.stackoverflow.com</a>

Is it possible to make something like

<a href=self.text>www.stackoverflow.com</a>

without using anything else (obviously, no scripts)? Is there any kind of shortcut?

user1583044
  • 323
  • 1
  • 4
  • 9
  • Nope, no way to do that. – j08691 Sep 18 '12 at 21:11
  • 1
    That's only possible with JavaScript, I'd imagine. Though, with CSS you could sort of do it the other way round, take the `href` attribute and make that the link text. (Though it wouldn't generate a clickable text, I think.) – David Thomas Sep 18 '12 at 21:12
  • @DavidThomas - A quick test shows that it generates clickable text in IE, Firefox, Opera and Safari, but not Chrome. – Alohci Sep 18 '12 at 23:01

4 Answers4

17

No, you need to have both the href attribute and a value between the a tags. Without using any scripts, it's not possible to refer to its own contents.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
jtheman
  • 7,421
  • 3
  • 28
  • 39
0

create an script/function for that

put a class to all of your anchors (i.e. "anchorTextAsHref" ), get all of them and modify the DOM structure,

just placing the text equals to whatever href has.

    let anchors=document.getElementsByClassName("anchorTextAsHref");
    for (let i = 0; i < anchors.length; i++) {
        anchors[i].text = anchors[i].href;
    }
-2

Use anchor link Useful Tips Section Create a link to the "Useful Tips Section" inside the same document:

Visit the Useful Tips Section

Shoaib Ud-Din
  • 4,614
  • 3
  • 23
  • 23
-3

I think you're looking for the Anchor Tag . You can use the syntax to link to it, if you reference it by using a <a href="link"> somewhere in the body.

Look here at the bottom for some examples:

http://www.w3schools.com/html/html_links.asp

j08691
  • 204,283
  • 31
  • 260
  • 272
John Swaringen
  • 731
  • 4
  • 11
  • 29
  • Nope, not looking for an anchor. Just looking for a way to get the href to equal the text. Thanks, though. – user1583044 Sep 18 '12 at 21:15
  • I was simply wondering if it was possible (without Javascript) to have a link's URL lifted from its text. The answer is no. – user1583044 Sep 18 '12 at 21:20