29

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?

3
  • Nope, no way to do that.
    – j08691
    Sep 18, 2012 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.) Sep 18, 2012 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, 2012 at 23:01

4 Answers 4

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.

0
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

-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

2
  • Nope, not looking for an anchor. Just looking for a way to get the href to equal the text. Thanks, though. Sep 18, 2012 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. Sep 18, 2012 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.