4

I'd like to know if it's possible to add an HTML anchor in a Stack Overflow answer or question.

For example, I made an edit in an answer and I put a link named "See the edit" redirecting to the Edit part of my answer.

Example of answer : (The following is not a real issue, I don't care about the code, I found it randomly. It's just for the example.)

Start of the example

This code is outdated, see the edit.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin gravida enim ex, eu luctus nibh fermentum a. Morbi ullamcorper nisi sit amet erat placerat, at posuere ex vestibulum. Pellentesque eget lacus rhoncus, iaculis dui a, tincidunt purus. Morbi eleifend ultricies sapien, ac laoreet sem fermentum vel. Pellentesque ultricies ligula eget nisi bibendum molestie at eu nulla. In id consequat mi. Sed vitae arcu ac nisl rutrum facilisis. Mauris ut ipsum eros. Nam fermentum risus ut euismod sagittis. Sed sem nibh, accumsan quis nisi et, pulvinar condimentum sapien. Curabitur quis pulvinar mi, sed dapibus eros. Nam euismod venenatis enim, vitae maximus nisl. Etiam in nisi ullamcorper, placerat enim a, blandit erat. Mauris vestibulum volutpat urna ac porttitor. Donec congue nisi ac maximus gravida.

Here's a few code :

Dim currentCaption As String
Dim lastCaption As String
Dim message As String
message = "This is scrolling text"
currentCaption = Combo1.Text
currentCaption = Right(currentCaption, Len(currentCaption) - 1)
Combo1.Text = currentCaption & Space(10) & message

EDIT :

I forgot one condition... Here's a working code:

Dim currentCaption As String
Dim lastCaption As String
Dim message As String
message = "This is scrolling text"
currentCaption = Combo1.Text
If Len(currentCaption) <> Len(message) Then
    currentCaption = Right(currentCaption, Len(currentCaption) - 1)
    Combo1.Text = currentCaption & Space(10) & message
Else
    Combo1.Text = Combo1.Text & Space(10) & message
End If

End of the example

Can I use the id="" attribute?
If yes, how?

Because I tried but it wasn't working. I noticed that when I click on a notification it redirects me to a link of the question with an anchor. (i.e. http://meta.stackoverflow.com/questions/303420/is-it-possible-to-add-html-anchor-in-a-stackoverflow-answer/303422?noredirect=1#comment238163_303422)

9
  • Why the downvotes ??
    – Drarig29
    Commented Aug 25, 2015 at 16:54
  • 11
    That's an example of a bad edit. There is no reason to add "Edit:" to your post like this, just put the code in. Definitely do not leave outdated code in your question. Your edit should leave the question looking like it has not been edited.
    – user229044 Mod
    Commented Aug 25, 2015 at 17:09
  • 1
    @meagar I don't care about the code. You didn't read the question. The code was random, just for the example...
    – Drarig29
    Commented Aug 25, 2015 at 17:12
  • I did read the question, and I'm telling you the premise of your question is wrong. It matters, if you're asking for a feature so that you can misuse it. Can you come up with some other use case that would actually warrant the feature in question?
    – user229044 Mod
    Commented Aug 25, 2015 at 17:12
  • 4
    Why don't you get rid of the entire example, and just show us the markup you're actually trying to produce. Is this about producing links such as <a id="something"></a> within your answer, so you can link to specific parts of your answer using http://stackoverflow.com/youranswer#something?
    – user229044 Mod
    Commented Aug 25, 2015 at 17:20
  • @meagar Yes, that's right.
    – Drarig29
    Commented Aug 25, 2015 at 17:52
  • 1
    The example is bad, but this might come in handy occasionally.
    – jscs
    Commented Aug 25, 2015 at 18:26
  • 1
    Yes the focus on this particular example is just missing the point. Marked as duplicate with link to another poorly worded question without a good answer. Ugh.
    – eric
    Commented Dec 14, 2015 at 7:16
  • I asked the question again, hopefully without inessential details, and responding to the attempted answer here: meta.stackoverflow.com/questions/312498/…
    – eric
    Commented Dec 17, 2015 at 1:25

1 Answer 1

1

You can use the <a> tag on Stack Exchange sites, but it doesn't look like you can use them as an anchor that you link to from another spot. It's only used as an href to link to other pages or posts.

Reference: What HTML tags are allowed on Stack Exchange sites?

Instead of adding a link to skip part of your answer, I'd just move the relevant part of the answer to the top, then either remove the original text or label it as outdated.

13
  • And how to create the link redirecting to my anchor ?
    – Drarig29
    Commented Aug 25, 2015 at 16:52
  • I may have misunderstood you. Are you trying to create an anchor in an answer, then link to that specific spot in another answer? Commented Aug 25, 2015 at 16:54
  • Yes. In another answer, or in the same one. Just to skip all the obsolete code.
    – Drarig29
    Commented Aug 25, 2015 at 16:56
  • @Drarig29 That might not be possible. Let me see if I can get this working. Commented Aug 25, 2015 at 16:58
  • I can't click the link below this answer. I don't have enough reputation points. In your opinion, why do I have been downvoted ??
    – Drarig29
    Commented Aug 25, 2015 at 16:59
  • The downvotes are probably because the question isn't that clear. Commented Aug 25, 2015 at 17:04
  • @Drarig29 The link is just plain HTML. <a href="http://meta.stackexchange.com/questions/1777/what-html-tags-are-allowed-on-stack-exchange-sites">What HTML tags are allowed on Stack Exchange sites?</a> Commented Aug 25, 2015 at 17:08
  • I'll edit the question.
    – Drarig29
    Commented Aug 25, 2015 at 17:10
  • 2
    I think we're talking about the ability to add empty <a> tags with IDs to link directly to parts of content, such as <a id="something"></a> and then linking with a URL like http://stackoverflow.com/a/...#something
    – user229044 Mod
    Commented Aug 25, 2015 at 17:18
  • @meagar Yes, I think that's right. Commented Aug 25, 2015 at 17:32
  • @meagar You understood perfectly. Do you have an answer ?
    – Drarig29
    Commented Aug 25, 2015 at 17:51
  • 1
    I have a very long answer with many parts (stackoverflow.com/a/34215918/1886357), and they are already in logical order. Rearranging wouldn't make sense (the flow is logical and every part is important). Seems strange we don't have the ability to put links to different parts. Some, not many, posts are long enough to deserve a ToC...
    – eric
    Commented Dec 14, 2015 at 6:19
  • Here is a great example of a long sprawling "question" that should have a table of contents (meta.stackoverflow.com/questions/307513/…), it is sort of a mess, a ToC would be very helpful, and without anchors you cannot link to different sections. You could have a ToC in text, but not links. It's like..take one of the best things about html (links), and kill it at SO.
    – eric
    Commented Dec 14, 2015 at 6:23

Not the answer you're looking for? Browse other questions tagged .