-1

I am having trouble with the anchor tag of HTML. I have something like this:

  1. Topic1
  2. Topic2
  3. Topic3

where Topic1, Topic2 and Topic3 are the link texts. On clicking any of these, it will take me to the content.html page but the content of this page differs only on the text which is clicked (ie.) how do I get the link text in the content.html page?

On an update to the database I will have more topics generated. So I want this link to function dynamically.

halfer
  • 19,824
  • 17
  • 99
  • 186
Gayathri
  • 140
  • 11
  • You want to go on the same page with all links but different sub-topic on that page?? – Aashish Kumar Sep 16 '17 at 11:52
  • I want to go to same page for all the links but it's content entirely differs based on the link text – Gayathri Sep 16 '17 at 12:14
  • Why do you need to extract the text? Can't you just vary the URL? Just add a query parameter. – Martijn Pieters Sep 16 '17 at 12:29
  • Pro-tip: there's no need to add "please help" followed by a long string of hyper-caffeinated exclamation marks. This is merely begging and pleading, and that will just get you downvotes. – halfer Sep 17 '17 at 21:37

3 Answers3

0

Please include jquery before $('a').click(function(){ alert($(this).attr('href')); // or alert($(this).hash(); });

0

You have to send the text as a parameter (using the query string) to content.html page. Then, when content.html page loads, you can use javascript to extract the parameter from the query string, and populate your page.

Radu Ungureanu
  • 131
  • 1
  • 9
  • Is there a way only using html? I don't know jquery :( – Gayathri Sep 16 '17 at 11:26
  • You don't need to use jquery, plain javascript is enough. Check the answer at [this question](https://stackoverflow.com/questions/5422265/how-can-i-pre-populate-html-form-input-fields-from-url-parameters). – Radu Ungureanu Sep 16 '17 at 11:39
0

If you go to the page content.html of a particular website then the content.html file must have different sections whose id="topic1", id="topic2" and id="topic3".

<a href="https://www.example.com/content.html/#topic1">Topic1</a>
<a href="https://www.example.com/content.html/#topic2">Topic2</a>
<a href="https://www.example.com/content.html/#topic3">Topic3</a>

content.html

<div id="topic1">---contains----</div>
<div id="topic2">---contains----</div>
<div id="topic3">---contains----</div>
Aashish Kumar
  • 2,771
  • 3
  • 28
  • 43
  • Suppose on an update in the database I will have Topic1, Topic2, Topic3 and Topic4. Then how can I give it directly in the link with #topic1 etc.??? – Gayathri Sep 17 '17 at 06:41
  • Anchor links are OK if you have a JavaScript app on the target page, but not if you want to read the value in a server-side language. – halfer Sep 17 '17 at 21:36