Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:13:12+00:00 2026-05-20T18:13:12+00:00

I have a page so far with: <div id=x1>Text paragraph 1<link here></div> <div id=x2>Text

  • 0

I have a page so far with:

<div id="x1">Text paragraph 1<link here></div>
<div id="x2">Text paragraph 2<link here></div>
<div id="x3">Text paragraph 3<link here></div>

Where link here is like

<a href="google.com">google</a>

What I am trying to do is add a link to the bottom of each paragraph of text so that when it is clicked it displays an alert with the div id of that text block.

So for example, if someone clicks on the link at the bottom of text paragraph 2, then they will get an alert saying “x2”.

So far, I have only been able to think of a way involving an onclick event for each link in each div. But with 100 paragraphs this could become quite a lot and is messy code.

like

$('#x1').onclick(function(){
alert('x1');
});

How can I do this better?

The page is generated with php so I could put the div id’s anywhere in that text block area (even make a new div around the link if required)…

EDIT – Many good answers, I don’t know which to pick as best. I actually ended up using Loongawas for my purpose as its easy to make for my beginner level in php.

<div id='a1'>This text <a href="" onclick=tomato(1)>test</a>
</div>
<div id='a2'>This text <a href="" onclick=tomato(2)>test</a>
</div>
<div id='a3'>This text <a href="" onclick=tomato(3)>test</a>
</div>

and

function tomato(test){
alert(test);
};

Some of the others are incredibly interesting as they use higher functions. I’m going to spend the rest of the day looking into them. Thanks to all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:13:13+00:00Added an answer on May 20, 2026 at 6:13 pm

    You could make a javascript function that takes a variable and then pass the paragraph number to the function. If the paragraph was number two you could call

    myfunction(2);
    

    or is the number not the problem?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several divs like this: <div class=MenuList><a class=SiteLink href=page.aspx>My Link</a></div> The problem is
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
I am trying to change the text inside a div based on how far
I have a link on a page that toggles the visibility of a div.
I have a page which essentially looks like this: <div id=foo> <a>One</a>, <a>Two</a>, <a>Three</a>,
I have a page where there is a column and a content div, somewhat
I have a page with a Google Maps mashup that has pushpins that are
I have index page with navigation menu like this man caps shirt jeans woman

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.