-1

I would like to know if it is possible to create a link to a specific span in someone else's page. For putting on a website or blog one might create for themselves, or even a local page one uses to put links to something interesting they found maybe.To be more clear, I want the link this way so that when someone clicks on the link, it goes to a specific location on the page, mostly for a long page where you want someone to go directly to the relevant information - when that part of the page doesn't have an anchor element you can make use of. I am using Wikipedia as an example, even though it might not be the best example, because I know Wiki uses it's own way of doing certain things. Say you wanted to link to the Wiki page "List of fallacies" and the span for the sublist titled "Red herring fallacies".

The page link is : "https://en.wikipedia.org/wiki/List_of_fallacies"

Using Inspect Element, I got this for span :

<span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>

I tried to combine them like this :

<a href="https://en.wikipedia.org/wiki/List_of_fallacies<span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>">Red
herring logic fallacies list</a>

I am just wondering; am I a) doing it incorrectly for just using HTML, b) it can be done, but you have to use additional assets (CSS, JavaScript, etc), or c) it isn't possible to do at all?

I would like to do it using just HTML if possible, but if that is not possible, then I would appreciate it if someone can tell me how you might do it some other way - if it isn't impossible altogether. Thanks

Edit: My page is marked as a duplicate of answers to an earlier question, and from looking at the page it appears that this IS true. But I think my question heading itself was more clear to a beginner without much knowledge of advanced topics in creating webpages. Thanks for all of the help, and if the moderator believes my point is not relevant then please feel free to do whatever you do with duplicate questions.

Solitary
  • 1
  • 2
  • 1
    Possible duplicate of [How do I link to part of a page? (hash?)](http://stackoverflow.com/questions/2835140/how-do-i-link-to-part-of-a-page-hash) – Faegy Feb 09 '17 at 10:48
  • Faegy as I posted in my edit, I think I gave more detail in my question title. I also think I gave more detail in my question of the process I was using for what I was trying to do, which might make it easier for another beginner to recognize "Hey that's what I am trying to do with my DIV" or whatever. The other poster seemed to know more about HTML etc since his question was so short. Not trying to be argumentative, just stating my reasoning. – Solitary Feb 09 '17 at 11:25

3 Answers3

1

you are missing a close "> just before the span started and you are missing the anchor in your href like this #Red_herring_fallacies, because span has that ID

<a href="https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies">
  <span class="mw-headline" id="Red_herring_fallacies">Red herring fallacies</span>
  Redherring logic fallacies list
</a>
dippas
  • 58,591
  • 15
  • 114
  • 126
  • This doesn't navigate to the span. See my answer below. – Gezzasa Feb 09 '17 at 10:43
  • dippas, you have a good answer and pointed out an error as I had originally constructed the link. But when done your way, it opens the page at the top of the page and someone would have to find the specific information I wanted to target by having to scroll down and find it. Thanks for the information and the attempt to help though. – Solitary Feb 09 '17 at 11:12
  • @Solitary it doesn't happen in my snippet, have you clicked in my link? (BTW I'm doing exactly the same way as the correct answer) – dippas Feb 09 '17 at 11:16
  • dippas, you are correct, I had copied out the code and pasted it into the browser address bar, and edited out the stuff like a=href. For some reason it opened the page at the top. But when I clicked "run code snippet" and then clicked on the link, you are correct it did go right to the section I was interested in. Thanks, my mistake. – Solitary Feb 09 '17 at 11:33
  • Dippas, am I wrong or isn't your code snippet structured just a bit differently than Gezzasa's string? Not criticizing, it did work when I finally did it right after you told me the easy way to test it, seems like it is helpful because it shows how you can accomplish the same thing in yet another way :). – Solitary Feb 09 '17 at 11:56
  • The link is the same `https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies` – dippas Feb 09 '17 at 12:02
0

The span has an ID. Use that as the parameter in your URL in the link.

<a href="https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies">Red herring logic fallacies list</a>
Gezzasa
  • 1,443
  • 8
  • 17
  • 1
    Gezzasa I picked your answer because of 2 things, it reveals new information a beginner might not know and did what I wanted to happen, specifically when you use that link it opens the page directly at the relevant part of the long page I wanted to go to. – Solitary Feb 09 '17 at 11:09
  • @Solitary thank you. Glad it worked well for you and that you learnt something :). – Gezzasa Feb 09 '17 at 11:38
  • Gezzasa thanks again. That's what I love about these boards, most everyone is so helpful and they are great for those of us who don't have a lot of background to learn some very useful new information :). – Solitary Feb 09 '17 at 11:47
  • This site has saved me so many times before. We all try to give back to the community :). Soon you'll be posting answers too. – Gezzasa Feb 09 '17 at 11:59
0

To target an id you must add #theId at the end of your url.

The result will look ass follow:

<a href="https://en.wikipedia.org/wiki/List_of_fallacies#Red_herring_fallacies">
    Red herring logic fallacies list
</a>
Faegy
  • 942
  • 1
  • 12
  • 29
  • Faegy, your answer was basically the same as Gezzasa but I didn't realize at first what you meant by target #theId so Gezzasa's answer was a bit more clear to me. I do appreciate the answer and the information trying to help me. – Solitary Feb 09 '17 at 11:15